Ricordisamoa has uploaded a new change for review.

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

Change subject: Drop WdqBase and subclasses
......................................................................

Drop WdqBase and subclasses

The Wikidata Query Service is reliable and preferred to WikidataQuery.
Dropping support for the latter significantly decreases the amount of
unreachable code.

https://phabricator.wikimedia.org/T122706#2718182

Change-Id: I16584ba1304f306b54da0f9e6e21782a8f1e4a5f
---
M base.py
M chemistry.py
M nuclides.py
3 files changed, 2 insertions(+), 151 deletions(-)


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

diff --git a/base.py b/base.py
index bc01b1a..6d878f7 100644
--- a/base.py
+++ b/base.py
@@ -90,20 +90,6 @@
         raise NotImplementedError()
 
 
-class WdqBase:
-    """Load items from Wikidata Query."""
-
-    WDQ_API = 'http://wdq.wmflabs.org/api'
-
-    @classmethod
-    def get_wdq(cls):
-        return get_json(cls.WDQ_API, cls.get_query())
-
-    @classmethod
-    def get_query(cls):
-        raise NotImplementedError()
-
-
 class SparqlBase:
     """Load items from Wikidata SPARQL query service."""
 
diff --git a/chemistry.py b/chemistry.py
index 9ea7ac7..434634c 100644
--- a/chemistry.py
+++ b/chemistry.py
@@ -22,7 +22,7 @@
 from collections import defaultdict
 
 import data
-from base import BaseProvider, PropertyAlreadySetException, SparqlBase, 
TableCell, WdqBase, get_json
+from base import BaseProvider, PropertyAlreadySetException, SparqlBase, 
TableCell, get_json
 
 
 class ElementProvider(BaseProvider):
@@ -82,55 +82,6 @@
                     specials[period][i].__class__ = ElementCell  # XXX
                     special_series[sindex].append(specials[period][i])
         return elements, table, special_series, incomplete
-
-
-class WdqElementProvider(WdqBase, ElementProvider):
-    """Load elements from Wikidata Query."""
-    def __iter__(self):
-        wdq = self.get_wdq()
-        ids = ['Q%d' % item_id for item_id in wdq['items']]
-        entities = self.get_entities(ids, props='labels',
-                                     languages=self.language, 
languagefallback=1)
-        elements = defaultdict(Element)
-        subclass_of = defaultdict(list)
-        wdq['props'] = defaultdict(list, wdq.get('props', {}))
-        for item_id, datatype, value in wdq['props'][str(Element.number_pid)]:
-            if datatype != 'quantity':
-                continue
-            value = value.split('|')
-            if len(value) == 4:
-                value = list(map(float, value))
-                if len(set(value[:3])) == 1 and value[3] == 1 and value[0] == 
int(value[0]):
-                    elements[item_id].number = int(value[0])
-        for item_id, datatype, value in wdq['props'][str(Element.symbol_pid)]:
-            if datatype != 'string':
-                continue
-            elements[item_id].symbol = value
-        for item_id, datatype, value in 
wdq['props'][str(Element.subclass_pid)]:
-            if datatype != 'item':
-                continue
-            subclass_of[item_id].append(value)
-        for item_id, element in elements.items():
-            element.item_id = 'Q%d' % item_id
-            for prop in ('number', 'symbol'):
-                if not hasattr(element, prop):
-                    setattr(element, prop, None)
-            element.load_data_from_superclasses(subclass_of[item_id])
-            label = None
-            entity = entities.get(element.item_id)
-            if entity and 'labels' in entity and len(entity['labels']) == 1:
-                label = list(entity['labels'].values())[0]['value']
-            element.label = label
-            yield element
-
-    @classmethod
-    def get_query(cls):
-        pids = [str(getattr(Element, name))
-                for name in ('symbol_pid', 'subclass_pid', 'number_pid')]
-        return {
-            'q': 'claim[%d]' % Element.symbol_pid,
-            'props': ','.join(pids)
-        }
 
 
 class SparqlElementProvider(SparqlBase, ElementProvider):
diff --git a/nuclides.py b/nuclides.py
index d094b0c..bdc5fc6 100644
--- a/nuclides.py
+++ b/nuclides.py
@@ -22,7 +22,7 @@
 import operator
 from collections import defaultdict
 
-from base import BaseProvider, WdqBase, SparqlBase, 
PropertyAlreadySetException, TableCell
+from base import BaseProvider, SparqlBase, PropertyAlreadySetException, 
TableCell
 from units import time_in_seconds_from_claim, time_in_seconds
 
 
@@ -219,92 +219,6 @@
             magic_number = magic_result['magic_number']['value']
             magic_numbers.append(int(magic_number))
         return magic_numbers
-
-
-class WdqNuclideProvider(WdqBase, NuclideProvider):
-    """Load nuclides from Wikidata Query."""
-    def __iter__(self):
-        wdq = self.get_wdq()
-        ids = ['Q%d' % item_id for item_id in wdq['items']]
-        entities = self.get_entities(ids, props='labels|claims',
-                                     languages=self.language, 
languagefallback=1)
-        nuclides = defaultdict(Nuclide)
-        wdq['props'] = defaultdict(list, wdq.get('props', {}))
-        for item_id, datatype, value in 
wdq['props'][str(Nuclide.atomic_number_pid)]:
-            if datatype != 'quantity':
-                continue
-            value = value.split('|')
-            if len(value) == 4:
-                value = list(map(float, value))
-                if len(set(value[:3])) == 1 and value[3] == 1 and value[0] == 
int(value[0]):
-                    nuclides[item_id].atomic_number = int(value[0])
-        for item_id, datatype, value in 
wdq['props'][str(Nuclide.neutron_number_pid)]:
-            if datatype != 'quantity':
-                continue
-            value = value.split('|')
-            if len(value) == 4:
-                value = list(map(float, value))
-                if len(set(value[:3])) == 1 and value[3] == 1 and value[0] == 
int(value[0]):
-                    nuclides[item_id].neutron_number = int(value[0])
-        for item_id, nuclide in nuclides.items():
-            nuclide.item_id = 'Q%d' % item_id
-            for prop in ('atomic_number', 'neutron_number'):
-                if not hasattr(nuclide, prop):
-                    setattr(nuclide, prop, None)
-# ??            nuclide.load_data_from_superclasses(subclass_of[item_id])
-            label = None
-            entity = entities.get(nuclide.item_id)
-            if entity and 'labels' in entity and len(entity['labels']) == 1:
-                label = list(entity['labels'].values())[0]['value']
-            nuclide.label = label
-
-            if entity:
-                claims = entity['claims']
-                instance_prop = 'P%d' % Nuclide.instance_pid
-                if instance_prop in claims:
-                    instance_claims = claims[instance_prop]
-                    for instance_claim in instance_claims:
-                        class_id = 
instance_claim['mainsnak']['datavalue']['value']['numeric-id']
-                        if class_id == Nuclide.stable_qid:
-                            nuclide.classes.append('stable')
-
-            half_life = None
-            if entity:
-                claims = entity['claims']
-                hlprop = 'P%d' % Nuclide.half_life_pid
-                if hlprop in claims:
-                    hl_claims = claims[hlprop]
-                    for hl_claim in hl_claims:
-                        half_life = time_in_seconds_from_claim(hl_claim)
-            nuclide.half_life = half_life
-
-            if entity:
-                claims = entity['claims']
-                decay_prop = 'P%d' % Nuclide.decays_to_pid
-                if decay_prop in claims:
-                    decay_claims = claims[decay_prop]
-                    for decay_claim in decay_claims:
-                        if 'qualifiers' in decay_claim:
-                            decay_mode_prop = 'P%d' % Nuclide.decay_mode_pid
-                            qualifiers = decay_claim['qualifiers']
-                            if decay_mode_prop in qualifiers:
-                                for qualifier in qualifiers[decay_mode_prop]:
-                                    nuclide.decay_modes.append(
-                                        
qualifier['datavalue']['value']['numeric-id'])
-
-            yield nuclide
-
-    @classmethod
-    def get_query(cls):
-        pids = [str(getattr(Nuclide, name))
-                for name in ('atomic_number_pid', 'neutron_number_pid')]
-        return {
-            'q': 'claim[%d:(tree[%d][][%d])] AND noclaim[%d:%d]' %
-                 (Nuclide.instance_pid, Nuclide.isotope_qid,
-                  Nuclide.subclass_pid, Nuclide.instance_pid,
-                  Nuclide.isomer_qid),
-            'props': ','.join(pids)
-        }
 
 
 class Nuclide:

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I16584ba1304f306b54da0f9e6e21782a8f1e4a5f
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/ptable
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisa...@openmailbox.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to