Repository navigation
wikibase: initial somevalue novalue editing support - #5360
Conversation
wetneb
left a comment
There was a problem hiding this comment.
Very nice, congrats!
Do not forget to write unit tests as you go along - this part of the codebase has ample server-side tests so you should be able to imitate existing ones for most classes you touch.
09ca762 to
65ee36a
Compare
65ee36a to
b3d0784
Compare
| if (!existingSnak.getPropertyId().getId().equals(addedSnak.getPropertyId().getId())) { | ||
| return false; | ||
| } else if (existingSnak instanceof NoValueSnak && addedSnak instanceof NoValueSnak) { | ||
| } else if (existingSnak instanceof NoValueSnakImpl && addedSnak instanceof NoValueSnakImpl) { |
There was a problem hiding this comment.
@wetneb I'm not sure if this ever worked or if I have caused what makes this change necessary.
There was a problem hiding this comment.
I am surprised it is necessary actually! In which situations does it make a difference to check for NoValueSnakImpl instead of NoValueSnak? In general for this library the user (us) is expected to refer to the interfaces only, not their implementations, so this is a sign that something fishy is going on.
But yes, this code was indeed not used before, since we could not have an addedSnak that would be a NoValueSnak.
There was a problem hiding this comment.
In this case I never got the NoValueSnak variant to work for either addedSnak or existingSnak. Debugging indicated that only *Impl instances were passed around.
However, I think the normal value snaks were passed around correctly.
There was a problem hiding this comment.
Ok! I guess the tests should help us get this to work. For the naming, the *Impl instances are also instances of the corresponding interfaces, so I really think this should not make any difference. Because the interfaces are meant to be the things we use here, I would prefer if we did not refer to the implementations.
There was a problem hiding this comment.
Do you have suggestions for good tests here? I'm drawn to the JSON-blob based ones but they aren't the easiest to follow on my end.
There was a problem hiding this comment.
I would write at least something in WbStatementExprTest. Just copy one of the existing test cases there (for instance testEvaluate) and replace one of the cell contents (defined in setRow) by one of your magic constants. Then, construct the expected value with the appropriate No/SomeValueSnak. That should be fairly straightforward.
Then, for the SnakOnlyStatementMerger, you could follow the same strategy: copy some existing test case, change the some/both of the involved statements being matched to have some no value / somevalue case, and specify the expected matching result.
There was a problem hiding this comment.
WbStatementExprTest doesn't seem to test anything other than WbExpression as the evaluateTo method is inherited from WbExpressionTest? At best I could catch the new exceptions.
There was a problem hiding this comment.
No, it does test WbStatementExpr. The evaluateExpr method can indeed work with any WbExpression, it is a utility that is used in many test classes. In this case it is used to test WbStatementExpr via a wrapper defined in the test class.
There was a problem hiding this comment.
We still need to change this to use the interfaces and not the implementations, just as a matter of good practice. Note that we are defining FullyPropertySerializingNoValueSnak.java ourselves so we know those interfaces can have more implementations.
There was a problem hiding this comment.
Yeah sure, problem still is that changing to the interfaces break it.
|
@trnstlntk there are some implementation details left but it should already work as expected. |
|
I have tested it (on the user side) and it works great. One example edit: https://commons.wikimedia.org/w/index.php?title=File%3AKoninklijk_Theater_Tuscinski_%E2%80%93_cinema_organ_02.jpg&type=revision&diff=703109719&oldid=703088605 The workflow is ... "specific" but I think it makes sense. |
Just to emphasize: stated as such the workflow is very convoluted, but this is not the intended use case: this implementation is not meant to serve the case where the added value is constantly novalue/somevalue, but rather the case when this depends on which row. See the issue for a proposed workflow for constant novalue/somevalue (which could be added as a follow-up PR). |
| } else if (json.snaktype === "somevalue") { | ||
| $('<span>somevalue</span>').appendTo(container); | ||
| } else if (json.snaktype === "novalue") { | ||
| $('<span>novalue</span>').appendTo(container); |
There was a problem hiding this comment.
Since those strings are shown to the user, it would be good to:
- use user-friendly terms instead (Wikibase displays "unknown value" / "no value")
- make it possible to localize them with
$.i18n
There was a problem hiding this comment.
+1 I would suggest "some value" and "no value" as Commons does it.
| if ("#NOVALUE#".equals(cell.toString())) { | ||
| throw new SpecialValueNoValueException(); | ||
| } else if ("#SOMEVALUE#".equals(cell.toString())) { | ||
| throw new SpecialValueSomeValueException(); |
There was a problem hiding this comment.
Since the "#NOVALUE#" and "#SOMEVALUE#" Strings have a special meaning defined by this class, I still think it would be good to have them as public static final String in this class, to make them part of the public interface of this class. This could be reused in tests, initially.
| if (!existingSnak.getPropertyId().getId().equals(addedSnak.getPropertyId().getId())) { | ||
| return false; | ||
| } else if (existingSnak instanceof NoValueSnak && addedSnak instanceof NoValueSnak) { | ||
| } else if (existingSnak instanceof NoValueSnakImpl && addedSnak instanceof NoValueSnakImpl) { |
There was a problem hiding this comment.
We still need to change this to use the interfaces and not the implementations, just as a matter of good practice. Note that we are defining FullyPropertySerializingNoValueSnak.java ourselves so we know those interfaces can have more implementations.
|
Hi @Abbe98, are you still working on this? I just started a discussion on releasing 3.7-beta1: if you plan to finish this soon and want us to wait for you, let us know: https://forum.openrefine.org/t/releasing-3-7-beta1/214 |
|
I would merge this and release it in 3.7. I'll open a documentation PR for it too. |
|
Thanks @wetneb! 🚀 |
Part of #1713.
This makes it possible to set novalue / somevalue statements when editing by adding two "magic" keywords
#NOVALUE#and#SOMEVALUE#.Usage:
Known issues / remaining tasks:
Not all data types are supported (only properly tested with dates so far)Statement merger doesn't workPreview is blankImplementation details:
SpecialValueNoValueExceptionandSpecialValueSomeValueExceptionextendsSkipSchemaExpressionException, these should probably all instead extend a genericSchemaException