Ricordisamoa has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/263846

Change subject: ApiElementProvider: ignore items without chemical symbol as 
statement
......................................................................

ApiElementProvider: ignore items without chemical symbol as statement

Currently, any item with a link to Element.symbol_pid is considered a
chemical element, including items in which Element.symbol_pid is only
the value of a statement, like https://www.wikidata.org/wiki/Q102500.

Instead, any item without a symbol should be thrown away.

Also clarified that the items returned by get_elements_titles() are not
guaranteed to be chemical elements.

Change-Id: Id19b9f2286017c02c83104afc1b54095df578c8d
---
M chemistry.py
1 file changed, 7 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/tools/ptable 
refs/changes/46/263846/1

diff --git a/chemistry.py b/chemistry.py
index 4b515b8..78c0918 100644
--- a/chemistry.py
+++ b/chemistry.py
@@ -194,7 +194,8 @@
                 # FIXME
                 continue
             else:
-                yield element
+                if element is not None:
+                    yield element
 
     @staticmethod
     def get_claim_value(claim):
@@ -204,13 +205,13 @@
     def factory(cls, entity):
         claims = defaultdict(list, entity.get('claims', []))
         try:
+            symbol = cls.get_claim_value(claims['P%d' % Element.symbol_pid][0])
+        except IndexError:
+            return None
+        try:
             number = int(cls.get_claim_value(claims['P%d' % 
Element.number_pid][0])['amount'])
         except IndexError:
             number = None
-        try:
-            symbol = cls.get_claim_value(claims['P%d' % Element.symbol_pid][0])
-        except IndexError:
-            symbol = None
         if 'labels' in entity and len(entity['labels']) == 1:
             label = list(entity['labels'].values())[0]['value']
         else:
@@ -222,11 +223,7 @@
 
     @classmethod
     def get_elements_titles(cls):
-        """
-        Get titles of Wikidata items of chemical elements.
-
-        All items that link to Element.symbol_pid are considered chemical 
elements.
-        """
+        """Get titles of Wikidata items that link to Element.symbol_pid."""
         backlinks_query = {
             'action': 'query',
             'format': 'json',

-- 
To view, visit https://gerrit.wikimedia.org/r/263846
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id19b9f2286017c02c83104afc1b54095df578c8d
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/ptable
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to