More write methods - #479
Merged
Merged
Conversation
LeMyst
force-pushed
the
more-write
branch
3 times, most recently
from
May 4, 2023 13:54
b739def to
17d2cb1
Compare
LeMyst
force-pushed
the
more-write
branch
2 times, most recently
from
January 8, 2024 11:41
5de4009 to
fae9442
Compare
Add LexemeEntity.write_form(), write_sense(), write_forms() and write_senses() to add a Form or a Sense to an existing Lexeme with the wbladdform and wbladdsense actions, without sending the whole entity. - Forms and Senses are now iterable. - Form and Sense compare and hash by content (the id is ignored). - Refuse to add a Form/Sense that already has an id, or a Sense marked as removed; write_forms()/write_senses() skip them. - Support wbladdform/wbladdsense in the MockWikibase and add unit tests, plus an integration test (skipped without WikibaseLexeme). - Document the new methods in the README and lexeme_write notebook. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add methods to add a Form or a Sense to an existing Lexeme, without sending the whole entity with
wbeditentity.Changes
LexemeEntity.write_form(form)/write_sense(sense)add a single Form/Sense with thewbladdform/wbladdsenseactions. They acceptlogin,allow_anonymous,is_botand extra kwargs likewrite(), return the id assigned by the instance (e.g.L10-F2) and set it on the object.LexemeEntity.write_forms()/write_senses()add every Form/Sense of the Lexeme without an id, one request each.ValueErroris raised when the Lexeme has no id, when the Form/Sense already has one (it would be duplicated), or when the Sense is marked as removed.write_forms()/write_senses()skip these.FormsandSensesare now iterable.FormandSensenow compare and hash by content (representations/glosses, grammatical features, claims), the id is ignored.Behavior change
Until now
FormandSenseused the default identity comparison. With this PR two distinct objects holding the same content are equal and have the same hash:Form() == Form()is nowTrue, and asetofForm/Sensededuplicates by content. As the hash follows the content, a Form/Sense modified after being put in a set or used as a dict key won't be found anymore.Tests
MockWikibasesupportswbladdformandwbladdsense, with unit tests for the new methods, iteration, equality and hashing.TestLexemeFormsAndSensesintest/integration/test_wikibase_roundtrip.py(skipped when the instance doesn't have the WikibaseLexeme extension). It hasn't been run against a real instance yet.Documentation
notebooks/lexeme_write.ipynb: new cells usingwrite_form(),write_sense()andwrite_senses().Changelog
LexemeEntity.write_form(),write_sense(),write_forms()andwrite_senses()to add Forms and Senses to an existing Lexeme.FormsandSensesare iterable.FormandSensecompare and hash by content instead of identity.🤖 Generated with Claude Code