[MediaWiki-commits] [Gerrit] labs...ptable[master]: Drop WdqBase and subclasses

2016-10-15 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

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
M units.py
4 files changed, 3 insertions(+), 161 deletions(-)

Approvals:
  Ricordisamoa: Looks good to me, approved
  jenkins-bot: Verified



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..76e83ae 100644
--- a/nuclides.py
+++ b/nuclides.py
@@ -22,8 +22,8 @@
 import operator
 from collections import defaultdict
 
-from base import BaseProvider, WdqBase, SparqlBase, 
PropertyAlreadySetException, TableCell
-from units import time_in_seconds_from_claim, time_in_seconds
+from base import BaseProvider, SparqlBase, PropertyAlreadySetException, 
TableCell
+from units import time_in_seconds
 
 
 class NuclideProvider(BaseProvider):
@@ -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 = 

[MediaWiki-commits] [Gerrit] labs...ptable[master]: Drop WdqBase and subclasses

2016-10-15 Thread Ricordisamoa (Code Review)
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',
-