Ricordisamoa has uploaded a new change for review.

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

Change subject: Drop explicit SPARQL prefixes from queries
......................................................................

Drop explicit SPARQL prefixes from queries

Most prefixes that are used in common queries are supported by the
engine without the need to explicitly specify them.

Change-Id: I9e6566fb223dd6feaab7da654b0e032b5fd48e64
---
M nuclides.py
1 file changed, 5 insertions(+), 22 deletions(-)


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

diff --git a/nuclides.py b/nuclides.py
index d094b0c..c270e7f 100644
--- a/nuclides.py
+++ b/nuclides.py
@@ -117,10 +117,7 @@
     """Load nuclide info from Wikidata Sparql endpoint."""
     def __iter__(self):
         nuclides = defaultdict(Nuclide)
-        nuclides_query = "PREFIX wdt: <http://www.wikidata.org/prop/direct/> \
-PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
-PREFIX wd: <http://www.wikidata.org/entity/> \
-SELECT ?nuclide ?atomic_number ?neutron_number ?label WHERE {{ \
+        nuclides_query = "SELECT ?nuclide ?atomic_number ?neutron_number 
?label WHERE {{ \
     ?nuclide wdt:P{0}/wdt:P{1}* wd:Q{2} ; \
              wdt:P{3} ?atomic_number ; \
              wdt:P{4} ?neutron_number ; \
@@ -142,9 +139,7 @@
             nuclides[nuclide_uri].half_life = None
             nuclides[nuclide_uri].item_id = nuclide_uri.split('/')[-1]
 
-        stable_query = "PREFIX wdt: <http://www.wikidata.org/prop/direct/> \
-PREFIX wd: <http://www.wikidata.org/entity/> \
-SELECT ?nuclide WHERE {{ \
+        stable_query = "SELECT ?nuclide WHERE {{ \
     ?nuclide wdt:P{0}/wdt:P{1}* wd:Q{2} ; \
              wdt:P{0} wd:Q{3} . \
 }}".format(Nuclide.instance_pid, Nuclide.subclass_pid, Nuclide.isotope_qid,
@@ -155,12 +150,7 @@
             if nuclide_uri in nuclides:
                 nuclides[nuclide_uri].classes.append('stable')
 
-        hl_query = "PREFIX wdt: <http://www.wikidata.org/prop/direct/> \
-PREFIX wd: <http://www.wikidata.org/entity/> \
-PREFIX wikibase: <http://wikiba.se/ontology#> \
-PREFIX psv: <http://www.wikidata.org/prop/statement/value/> \
-PREFIX p: <http://www.wikidata.org/prop/> \
-SELECT ?nuclide ?half_life ?half_life_unit WHERE {{ \
+        hl_query = "SELECT ?nuclide ?half_life ?half_life_unit WHERE {{ \
     ?nuclide wdt:P{0}/wdt:P{1}* wd:Q{2} ; \
              p:P{3} ?hl_statement . \
     ?hl_statement psv:P{3} ?hl_value . \
@@ -181,12 +171,7 @@
                         nuclide_result['half_life_unit']['value'])
                 # else - sparql returned more than 1 half-life value - problem?
 
-        decay_query = "PREFIX ps: <http://www.wikidata.org/prop/statement/> \
-PREFIX pq: <http://www.wikidata.org/prop/qualifier/> \
-PREFIX p: <http://www.wikidata.org/prop/> \
-PREFIX wdt: <http://www.wikidata.org/prop/direct/> \
-PREFIX wd: <http://www.wikidata.org/entity/> \
-SELECT ?nuclide ?decay_to ?decay_mode ?fraction WHERE {{ \
+        decay_query = "SELECT ?nuclide ?decay_to ?decay_mode ?fraction WHERE 
{{ \
     ?nuclide wdt:P{0}/wdt:P{1}* wd:Q{2} ; \
              p:P{3} ?decay_statement . \
     ?decay_statement ps:P{3} ?decay_to ; \
@@ -206,9 +191,7 @@
             yield nuclide
 
     def get_magic_numbers(self):
-        magic_query = "PREFIX wdt: <http://www.wikidata.org/prop/direct/> \
-PREFIX wd: <http://www.wikidata.org/entity/> \
-SELECT ?magic_number WHERE {{ \
+        magic_query = "SELECT ?magic_number WHERE {{ \
     ?number wdt:P{0} wd:Q{1} ; \
             wdt:P{2} ?magic_number . \
 }} ORDER by ?magic_number".format(Nuclide.instance_pid, Nuclide.magic_qid,

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9e6566fb223dd6feaab7da654b0e032b5fd48e64
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