Skip to content

Conversation

@robertsilen
Copy link

With the help of Cursor AI and Claude, I addeed support for adding external-id claims to lexemes. I have been using this version of LexData now for creating lexemes and it works, see e.g. P12682 in L1463924. I have not tested other cases, not sure what they could be. As the solution is generated by GenAI, I don't have a deep understanding if the solution is sound - could you @Nudin can evaluate if this is suitable to merge with the project? The following is generated by GenAI and review by me:

Problem
LexData currently doesn't support adding external-id claims to lexemes. When attempting to add external-id properties (like P12682) to lexemes, the API returns errors like:

  • "invalid-snak" when using wbcreateclaim with plain string values
  • "Type 'external-id' is unsupported" when using wbeditentity

Root Cause
The Wikidata API expects external-id values to be sent as JSON-encoded strings (e.g., '"value"') rather than plain strings ('value'). Additionally, the pure_value property in the Claim class didn't handle the external-id data type.

Solution

  1. Added external-id support in utils.py: Extended buildDataValue() to handle external-id data type correctly
  2. Fixed pure_value in claim.py: Added support for extracting values from external-id claims
  3. Updated entity.py: Modified setClaim to JSON-encode external-id values before sending to API
  4. Enhanced setEntityClaim: Added detection and proper handling of external-id properties

Changes Made

  • LexData/utils.py: Added "external-id" to supported data types
  • LexData/claim.py: Added external-id case in pure_value property
  • LexData/entity.py: Updated claim creation logic to handle external-id properly

Testing
Verified that external-id claims can now be successfully added to lexemes:

claim = LexData.Claim(propertyId="P12682", value="some_external_id")
lexeme.addClaims([claim])

Questions for Review

  1. Is this the right approach? I used wbcreateclaim for lexemes (which works) rather than wbeditentity (which fails with external-id). Should we investigate why wbeditentity doesn't support external-id on lexemes?
  2. API consistency: The Wikidata API seems to have different behavior for external-id properties on lexemes vs items. Is this expected, or should we file a bug report with Wikidata?
  3. Error handling: Should we add more specific error handling for external-id properties, or is the current approach sufficient?

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