3
$\begingroup$

The advent of Mathematica in the cloud and linguistic input potentially transforms expectations of the Wolfram Language's programming model and its inherent robustness. An example of this comes form trying to bridge what seems to be a disconnect in the language between its Mathematica and WolframAlpha invocations. Consider CountryData where up until 2008 you can find the GDP of the US in Mathematica :

CountryData["UnitedStates", {"GDP", 2008}]

enter image description here

but surprisingly not thereafter (The great recession was bad - but surely not that catastrophic) :

CountryData["UnitedStates", {"GDP", 2009}]

(* Missing["NotAvailable"] *)

In WolframAlpha however, GDP is available for 2009 (reassuringly, life continued) as can be seen by typing "US GDP in 2009" into its web page before receiving back a raft of other information. This can be accessed within Mathematica where in particular, the GDP information can be zeroed in via the "Result" argument:

 WolframAlpha["US GDP in 2009", "Result"]

enter image description here

Now you can integrate this functionality by doing an apriori check on this data's availability within Mathematica and then redefining CountryData to grab it from WolframAlpha if necessary.

SetAttributes[CheckCountryData, HoldAll];

CheckCountryData[CountryData["UnitedStates", {"GDP", yr_}]] := 
With[{temp = CountryData["UnitedStates", {"GDP", yr}]},
 If[Head@temp === Missing,
      Unprotect@CountryData;
      CountryData["UnitedStates", {"GDP", yr}] := 
      WolframAlpha[yr // StringTemplate["US GDP in `1`"], "Result"];
      Protect@CountryData,
      temp]
    ];

CheckCountryData[CountryData["UnitedStates", {"GDP", #}]] & /@Range[2008,2020];

Table[{
  yr // StringTemplate["US GDP in `1`"], 
     With[{yr = yr}, 
  Defer@CountryData["UnitedStates", {"GDP", yr}]], 
  CountryData["UnitedStates", {"GDP", yr}]},
      {yr, 2008, 2020}] // TableForm

enter image description here

Now maybe CountryData will be updated in Mathematica and/or the two data sources more tightly integrated at some point but the broader point remains; consider how the programming model has been changed along with the language's robustness, reliability and repeatability. The input/output/complexity/programming experience is now more fluid depending, for example, on the constancy/consistency of linguistic interpretations; the speed/availability of cloud connections, the date, W/A compatibility etc.

Note that instead of a WolframAlpha call, Free-Form input followed by its Entity interpretation can be used

enter image description here

and while this perhaps improves the interpreting consistency it is also less concise and less amenable for ready parametrization (e.g. used for a range of years instead of only 2009).

One part of Mathematica's programming language morphing into an expanded Wolfram Language seems to incorporate an ether-like presence, an interoperability (including with natural language) but I'm wondering if anyone has successfully/unsuccessfully integrated Free-Form input and/or widespread Entity/WolframAlpha calls in any significant way?

$\endgroup$
  • $\begingroup$ Have you tried raising a query with WRI support? Might be useful to get the official answer. $\endgroup$ – Gordon Coale Mar 18 '15 at 8:23
  • $\begingroup$ I'm not sure there is an official answer when it comes to the interplay between natural language and programming languages but yes the CountryData lagging is probably worth flagging. Unfortunately, though this data curation issue is a much wider challenge since a pretty significant percentage of calls are in fact Missing[NotAvailable] (particularly non-US data) which I suspect reflects current priorities/curation limitations. $\endgroup$ – Ronald Monson Mar 18 '15 at 9:36
  • 1
    $\begingroup$ A major issue with substituting in W|A data for Country data seems to be ensuring Apples are Apples. eg WolframAlpha["US GDP in 2008","Result"] <> CountryData["UnitedStates",{"GDP",2008}]. 1.46 tn vs 1.4 tn $\endgroup$ – Gordon Coale Mar 23 '15 at 15:47
  • $\begingroup$ I raised the missing country data as an issue with WRI and its been passed onto to the devs. Will wait and see... $\endgroup$ – Gordon Coale Mar 24 '15 at 9:27

Your Answer

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

Browse other questions tagged or ask your own question.