Skip to content

More write methods - #479

Merged
LeMyst merged 1 commit into
masterfrom
more-write
Sep 19, 2026
Merged

LeMyst merged 1 commit into
masterfrom
more-write

Conversation

@LeMyst

@LeMyst LeMyst commented Dec 27, 2022

Copy link
Copy Markdown
Owner

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 the wbladdform / wbladdsense actions. They accept login, allow_anonymous, is_bot and extra kwargs like write(), 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.
  • A ValueError is 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.
  • Forms and Senses are now iterable.
  • Form and Sense now compare and hash by content (representations/glosses, grammatical features, claims), the id is ignored.

Behavior change

Until now Form and Sense used the default identity comparison. With this PR two distinct objects holding the same content are equal and have the same hash: Form() == Form() is now True, and a set of Form/Sense deduplicates 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

  • MockWikibase supports wbladdform and wbladdsense, with unit tests for the new methods, iteration, equality and hashing.
  • New integration test TestLexemeFormsAndSenses in test/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

  • README: new section Add a form or a sense to an existing lexeme.
  • notebooks/lexeme_write.ipynb: new cells using write_form(), write_sense() and write_senses().

Changelog

  • Add LexemeEntity.write_form(), write_sense(), write_forms() and write_senses() to add Forms and Senses to an existing Lexeme.
  • Forms and Senses are iterable.
  • Form and Sense compare and hash by content instead of identity.

🤖 Generated with Claude Code

@LeMyst
LeMyst force-pushed the more-write branch 3 times, most recently from b739def to 17d2cb1 Compare May 4, 2023 13:54
@LeMyst
LeMyst force-pushed the more-write branch 2 times, most recently from 5de4009 to fae9442 Compare January 8, 2024 11:41
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>
@LeMyst
LeMyst merged commit 532fea3 into master Sep 19, 2026
15 checks passed
@LeMyst
LeMyst deleted the more-write branch September 19, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant