Wikidata / Wikidata-Toolkit

Java library to interact with Wikibase
https://www.mediawiki.org/wiki/Wikidata_Toolkit
Apache License 2.0
375 stars 99 forks source link

Support snak and reference hashes #319

Open wetneb opened 6 years ago

wetneb commented 6 years ago

The data model should be able to store reference and snak hashes, when they are provided. This is necessary if we want to implement granular editing actions which need to identify parts of statements.

Hashes should not be required to construct the relevant objects as they are omitted in some JSON payloads (such as the dumps).

Tanish-Gupta commented 4 years ago

Hi, Is this issue still open for contribution? I am looking to contribute to it. From my understanding, we pass references to makeStatement() in Datamodel. I looked at the JSON for a statement, and there's one field called mainsnak and another called snak (and hash as well) within references. Can you confirm if we are looking to store the parameter - List references passed to the makeStatement()?

If yes, do we intend to make store these as a data member of Datamodel class itself?

Thank you

wetneb commented 4 years ago

Can you confirm if we are looking to store the parameter - List references passed to the makeStatement()?

I do not understand this question, sorry. I cannot parse it.

If yes, do we intend to make store these as a data member of Datamodel class itself?

No, nothing should be stored in the Datamodel class: this is just a helper to create other classes. Hashes should be stored in Snak and Reference classes.

Tanish-Gupta commented 4 years ago

I do not understand this question, sorry. I cannot parse it.

By this I meant that there is a parameter List of references passed to makeStatement() method in Datamodel class, so my question was that do we need to store it? But, your next statement made it clear. Thank you

So, I have come up with the following solution - We can have a string variable "hash" and include it in the json only when it is not Null, in both ReferenceImpl and SnakImpl classes

image

Then. create a function to deserialize them

image

image

This way the hashes are stored only when they are provided.

Can you please confirm if this fulfils the requirement ?

Thank you

wetneb commented 4 years ago

Yes this looks great to me! By the way, the best way to get feedback on your code changes is to submit them as a pull request (rather than including them as screenshots). Pull requests do not have to be final, you can always make changes to the pull request after review, or even start a new one from scratch if the direction was inappropriate.