Repository: LeMyst/WikibaseIntegrator

Issue:
add reset_id helper method
as a user I dont want to think about how to reset an id
See https://github.com/LeMyst/WikibaseIntegrator/issues/471

Discussion:

Patch:
diff --git a/wikibaseintegrator/datatypes/form.py b/wikibaseintegrator/datatypes/form.py
index f1e53e8..f82edf7 100644
--- a/wikibaseintegrator/datatypes/form.py
+++ b/wikibaseintegrator/datatypes/form.py
@@ -57,3 +57,9 @@ class Form(BaseDataType):
 
     def get_sparql_value(self) -> str:
         return self.mainsnak.datavalue['value']['id']
+
+    def get_lexeme_id(self) -> str:
+        """
+        Return the lexeme ID of the Form
+        """
+        return self.mainsnak.datavalue['value']['id'].split('-')[0]
diff --git a/wikibaseintegrator/datatypes/sense.py b/wikibaseintegrator/datatypes/sense.py
index f26f7ac..7234276 100644
--- a/wikibaseintegrator/datatypes/sense.py
+++ b/wikibaseintegrator/datatypes/sense.py
@@ -46,3 +46,9 @@ class Sense(BaseDataType):
 
     def get_sparql_value(self) -> str:
         return self.mainsnak.datavalue['value']['id']
+
+    def get_lexeme_id(self) -> str:
+        """
+        Return the lexeme ID of the Sense
+        """
+        return self.mainsnak.datavalue['value']['id'].split('-')[0]
diff --git a/wikibaseintegrator/models/claims.py b/wikibaseintegrator/models/claims.py
index 5be50cc..f27cb4c 100644
--- a/wikibaseintegrator/models/claims.py
+++ b/wikibaseintegrator/models/claims.py
@@ -131,7 +131,8 @@ class Claims(BaseModel):
 class Claim(BaseModel):
     DTYPE = 'claim'
 
-    def __init__(self, qualifiers: Optional[Qualifiers] = None, rank: Optional[WikibaseRank] = None, references: Optional[Union[References, List[Union[Claim, List[Claim]]]]] = None, snaktype: WikibaseSnakType = WikibaseSnakType.KNOWN_VALUE) -> None:
+    def __init__(self, qualifiers: Optional[Qualifiers] = None, rank: Optional[WikibaseRank] = None,
+                 references: Optional[Union[References, List[Union[Claim, List[Claim]]]]] = None, snaktype: WikibaseSnakType = WikibaseSnakType.KNOWN_VALUE) -> None:
         """
 
         :param qualifiers:
@@ -309,6 +310,12 @@ class Claim(BaseModel):
 
         return True
 
+    def reset_id(self):
+        """
+        Reset the ID of the current claim
+        """
+        self.id = None
+
     # TODO: rewrite this?
     def __contains__(self, item):
         if isinstance(item, Claim):


Test patch:
diff --git a/test/test_entity_lexeme.py b/test/test_entity_lexeme.py
index 2e7511b..02346c5 100644
--- a/test/test_entity_lexeme.py
+++ b/test/test_entity_lexeme.py
@@ -1,6 +1,7 @@
 import unittest
 
 from wikibaseintegrator import WikibaseIntegrator
+from wikibaseintegrator.datatypes import Form, Sense
 from wikibaseintegrator.wbi_config import config as wbi_config
 
 wbi_config['USER_AGENT'] = 'WikibaseIntegrator-pytest/1.0 (test_entity_lexeme.py)'
@@ -48,3 +49,7 @@ class TestEntityLexeme(unittest.TestCase):
         assert wbi.lexeme.new(language='Q397').language == 'Q397'
         assert wbi.lexeme.new(language='397').language == 'Q397'
         assert wbi.lexeme.new(language=397).language == 'Q397'
+
+    def test_get_lexeme_id(self):
+        assert Form(value='L123-F123', prop_nr='P16').get_lexeme_id() == 'L123'
+        assert Sense(value='L123-S123', prop_nr='P16').get_lexeme_id() == 'L123'
diff --git a/test/test_wbi_core.py b/test/test_wbi_core.py
index 1f5343a..0bf8604 100644
--- a/test/test_wbi_core.py
+++ b/test/test_wbi_core.py
@@ -291,3 +291,10 @@ class TestWbiCore(unittest.TestCase):
 
     def test_get_qualifier_properties(self):
         self.assertTrue(len(self.common_item.claims.get(property='P2067')))
+
+    def test_claim_reset_id(self):
+        item = wbi.item.get('Q582')
+        claim = item.claims.get('P31')[0]
+        assert claim.id is not None
+        claim.reset_id()
+        assert claim.id is None