6

I'm trying to retrieve some basic informations from chemical elements stored in wikidata to create an interactive periodic table.

It's my first attempt to use wikidata, so I've understood how to get properties stored directly inside a chemical element(here is the hydrogen wikidata page) like atomic number or symbol, here's the code modified from the example:

Chemical elements and their isotopes by number of neutrons (min/max)

SELECT ?element (SAMPLE(?symbol) AS ?symbol) (SAMPLE(?protons) AS ?protons) (SAMPLE(?mass) AS ?mass) (SAMPLE(?group) AS ?group) (SAMPLE(?period) AS ?period)
WHERE
{
  ?element wdt:P31 wd:Q11344;
           wdt:P1086 ?protons;
           wdt:P246 ?symbol.
}
GROUP BY ?element
ORDER BY ?protons

But I also need to get the position inside the periodic table know as group and period.

The chemical element page states that for example the hydrogen element is an instance of group 1 element (Q19557), and period 1 element (Q191936) but I can't figure out how to get these numbers, directly in the json response.

Edit 1 I tried to add a series ordinal property to groups in order to retrieve these numbers. For example see Group 15. However, I can't figure out how to get these numbers. Sorry for my ignorance!

  • re Edit 1 - I can't get them either. It doesn't seem to be a direct property of the group instance. – chrisis Dec 22 '16 at 13:27
6

I think this is close to what you want but there doesn't seem to be a property for group or period as a number.

SELECT ?element ?elementLabel ?symbol  ?protons ?group ?groupLabel ?period ?periodLabel
WHERE
{
  ?element wdt:P31 wd:Q11344;
           wdt:P1086 ?protons;
           wdt:P246 ?symbol.
  OPTIONAL {?element wdt:P279 ?group .
            ?group wdt:P31 wd:Q83306 .}
  OPTIONAL {?element wdt:P279 ?period .
            ?period wdt:P31 wd:Q101843 .}
     SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
}

ORDER BY ?protons
  • Thanks for your answer @chrisis, it's a good solution with the current organisation of chemical elements data. I think it could be better if we improve relationship inside chemical elements in wikidata. I'll propose some modifications to this data to the wikidata community. – Ben Dec 14 '16 at 7:42
4

Using the series ordinal added to the chemical groups, I can extract the group and period numbers with this query.

SELECT ?element ?symbol  ?protons ?group ?groupNumber ?period ?periodNumber
WHERE
{
  ?element wdt:P31 wd:Q11344 ;
       wdt:P1086 ?protons ;
       wdt:P246 ?symbol ;
       wdt:P279 ?group ;
       wdt:P279 ?period .

  OPTIONAL {
  ?group wdt:P31 wd:Q83306 ;
     p:P31 [pq:P1545 ?groupNumber] .
  } FILTER( ?group != ?period ) .

  ?period wdt:P31 wd:Q101843 ;
     p:P31 [pq:P1545 ?periodNumber] .

}

ORDER BY ?protons

However the chemical data in wikidata seems still messy and need to be better organized.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.