計算機科学のブログ

知識を広げる MathematicaでWolfram|Alphaのデータを使用する SemanticInterpretation、自由形式入力、CityDataコマンド、Entity、Properties、EntityVaue、猫(Singapura、シンガプーラ)の画像

ハンズ・オン・スタートMathematica® -Wolfram言語™によるプログラミング (C・ヘイスティング(著)、K・ミショー(著)、M・モリソン(著)、ウルフラム・リサーチ(翻訳)、丸善出版)の第2部(知識を広げる)、第22章(MathematicaでWolfram|Alphaのデータを使用する)の練習問題1、2、3、4、5、6、7、8、9、10の解答を求めてみる。

SemanticInterpretation["big apple"]
Output
InputForm[%]
Entity["City", {"NewYork", "NewYork", "UnitedStates"}]
Entity["City", {"NewYork", "NewYork", "UnitedStates"}]["Population"]
Output
WolframAlpha["top three cities in US"]
Output
INputForm[%]
Output

Terminal、WolframScriptでの出力

{{{Input, 1}, Plaintext} -> top 3 cities | by city population, 
                                    in United States
 
>    {{Result, 1}, Plaintext} -> 1 | New York City | 8.623 million people | , 
                                 2 | Los Angeles | 4 million people | 
                                 3 | Chicago | 2.716 million people | 
 
>    {{Population:CityData, 1}, Plaintext} -> 
 
>      | New York City | Los Angeles | Chicago                                       city population | 8.623 million people (country rank: 1st) (2017) | 4       
      >   million people (country rank: 2nd) (2017) | 2.716 million people       
      >   (country rank: 3rd) (2017)
      urban area population | 17.8 million people (New York urban area)       
      >   (country rank: 1st) (2000) | 11.79 million people (Los Angeles urban       
      >   area) (country rank: 2nd) (2000) | 8.308 million people (Chicago       
      >   urban area) (country rank: 3rd) (2000)
      metro area population | 19.02 million people (New York metro area)       
      >   (country rank: 1st) (2011) | 12.94 million people (Los Angeles metro       
      >   area) (country rank: 2nd) (2011) | 9.505 million people (Chicago       
      >   metro area) (country rank: 3rd) (2011)
 
>     , {{Distances:CityData, 1}, Plaintext} -> 
 
>      | distance | flight time                                               , 
      New York City to Los Angeles | 3966 km (kilometers) | 4 hours 30 minutes
      Los Angeles to Chicago | 2820 km (kilometers) | 3 hours 10 minutes
      total | 6786 km (kilometers) | 7 hours 40 minutes
      (assuming direct flight path at 890 km/h)
 
>    {{AdministrativeRegions:CityData, 1}, Plaintext} -> 
 
>      | counties | region
      New York City | Kings County (Brooklyn) (30.8% of city population) |       
      >   Queens County (Queens) (27.8% of city population) | New York County       
      >   (Manhattan) (19.2% of city population) | Bronx County (The Bronx)       
      >   (16.6% of city population) | Richmond County (Staten Island) (5.5% of       
      >   city population) | New York
      Los Angeles | Los Angeles County | California
      Chicago | Cook County | Illinois
 
>     , {{AdministrativeRegions:CityData, 2}, Plaintext} -> 
 
>       | country                , 
      (all cases) | United States
 
>    {{CurrentTime:CityData, 1}, Plaintext} -> 
 
>     New York City | 1:43 am EDT | Tuesday, September 8, 2020, 
      Los Angeles | 10:43 pm PDT | Monday, September 7, 2020
      Chicago | 12:43 am CDT | Tuesday, September 8, 2020
 
>    {{ACSPercentageEntrainments:ACSData, 1}, Plaintext} -> 
 
>      | New York City | Los Angeles | Chicago                                       race | white: 42.8% | black/African American: 24.3% | other: 15.1% | ...       
      >   | white: 52.2% | other: 22.9% | Asian: 11.7% | ... | white: 49.1% |       
      >   black/African American: 30.5% | other: 11.2% | ...
      Hispanic origin | 29.1% | 48.7% | 29%
      US citizens | 83.3% | 79.7% | 88.4%
 
>     , {{ACSEducationEntrainments:ACSData, 1}, Plaintext} -> 
 
>      | New York City | Los Angeles | Chicago
      college degree and above | 43.1% (1.14 × national average) | 39.1% (1.03       
      >   × national average) | 43.2% (1.14 × national average)
      high school diploma | 24.1% (0.867 × national average) | 19.5% (0.702 ×       
      >   national average) | 22.9% (0.825 × national average)
      less than high school diploma | 18.9% (1.41 × national average) | 23.6%       
      >   (1.77 × national average) | 16.2% (1.21 × national average)
      (for population age 25 and older)
 
>     , {{ACSIncomeEntrainments:ACSData, 1}, Plaintext} -> 
 
>      | New York City | Los Angeles | Chicago                                       median household income | $57782 per year (US dollars per year) (1.04 ×       
      >   national average) | $54501 per year (US dollars per year) (0.985 ×       
      >   national average) | $52497 per year (US dollars per year) (0.949 ×       
      >   national average)
      per capita income | $35761 per year per person (US dollars per year per       
      >   person) (1.2 × national average) | $31563 per year per person (US       
      >   dollars per year per person) (1.06 × national average) | $32560 per       
      >   year per person (US dollars per year per person) (1.09 × national       
      >   average)
      population below poverty line | 19.6% (1.3 × national average) | 20.4%       
      >   (1.35 × national average) | 20.6% (1.37 × national average)
 
>     , {{EconomicProperties:CityData, 1}, Plaintext} -> 
 
>      | New York City | Los Angeles | Chicago
      cost of living index | 2.5 × national average (Quarter 1 2020) | 1.5 ×       
      >   national average (Quarter 1 2020) | 1.2 × national average (Quarter       
      >   4 2019)
      median home price | $465700 (New York metro area) (annual change: +4.68%)       
      >   (2013) | $405600 (Los Angeles metro area) (annual change: +23.84%)       
      >   (2013) | $191300 (Chicago metro area) (annual change: +9.13%) (2013)
      unemployment rate | 20% (July 2020) | 18.5% (July 2020) | 15% (July 2020)
      total sales tax rate | 8.875% (2020) | 9.5% (2020) | 10.25% (2020)
 
>     , {{QualityOfLife:CityData, 1}, Plaintext} -> 
 
>      | New York City | Los Angeles | Chicago                                       total rate of violent crime | 1.5 × national average (2015) | 2 ×       
      >   national average (2017) | 2.9 × national average (2017)
      total rate of property crime | 0.64 × national average (2015) | 1.1 ×       
      >   national average (2017) | 1.4 × national average (2017)
      average daily traffic delay | 12 minutes per person per day | 13 minutes       
      >   per person per day | 10 minutes per person per day
 
>     , {{GeographicProperties:CityData, 1}, Plaintext} -> 
 
>      | elevation | area | population density                               , 
      New York City, New York | 10 m | 783.84 km^2 | 11001 people per square       
      >   kilometer
      Los Angeles, California | 89 m | 1213.9 km^2 | 3295 people per square       
      >   kilometer
      Chicago, Illinois | 179 m | 589.57 km^2 | 4608 people per square       
      >   kilometer
 
>    {{Input, 1}, Input} -> 
 
>     HoldComplete[EntityClass[City, 
 
>       {EntityProperty[City, Country] -> Entity[Country, UnitedStates], 
 
>        EntityProperty[City, Population] -> TakeLargest[3]}]], 
 
>    {{Population:CityData, 1}, Input} -> 
 
>     HoldComplete[Dataset[EntityValue[{Entity[City, 
 
>          {NewYork, NewYork, UnitedStates}], 
 
>         Entity[City, {LosAngeles, California, UnitedStates}], 
 
>         Entity[City, {Chicago, Illinois, UnitedStates}]}, 
 
>        {EntityProperty[City, Population], EntityProperty[City, Population]}, 
 
>        PropertyEntityAssociation]]], 
 
>    {{AdministrativeRegions:CityData, 1}, Input} -> 
 
>     HoldComplete[Dataset[EntityValue[{Entity[City, 
 
>          {NewYork, NewYork, UnitedStates}], 
 
>         Entity[City, {LosAngeles, California, UnitedStates}], 
 
>         Entity[City, {Chicago, Illinois, UnitedStates}]}, 
 
>        {EntityProperty[City, County]}, EntityPropertyAssociation]]], 
 
>    {{ACSPercentageEntrainments:ACSData, 1}, Input} -> 
 
>     HoldComplete[Dataset[EntityValue[{Entity[City, 
 
>          {NewYork, NewYork, UnitedStates}], 
 
>         Entity[City, {LosAngeles, California, UnitedStates}], 
 
>         Entity[City, {Chicago, Illinois, UnitedStates}]}, 
 
>        {EntityProperty[City, Population, 
 
>          {Race -> Default, HispanicOrigin -> Default, 
 
>           CitizenshipStatus -> TotalCitizens, Percent -> Main}]}, 
 
>        PropertyEntityAssociation]]], 
 
>    {{ACSEducationEntrainments:ACSData, 1}, Input} -> 
 
>     HoldComplete[Dataset[EntityValue[{Entity[City, 
 
>          {NewYork, NewYork, UnitedStates}], 
 
>         Entity[City, {LosAngeles, California, UnitedStates}], 
 
>         Entity[City, {Chicago, Illinois, UnitedStates}]}, 
 
>        {EntityProperty[City, PopulationByEducationalAttainment, 
 
>          {EducationAttainmentRange -> Associate-Doctorate, Percent -> Main}], 
 
>         EntityProperty[City, PopulationByEducationalAttainment, 
 
>          {EducationAttainment -> HighSchool, Percent -> Main}], 
 
>         EntityProperty[City, PopulationByEducationalAttainment, 
 
>          {EducationAttainmentRange -> NoSchooling-Twelfth, Percent -> Main}]} 
>         , PropertyEntityAssociation]]], 
 
>    {{ACSIncomeEntrainments:ACSData, 1}, Input} -> 
 
>     HoldComplete[Dataset[EntityValue[{Entity[City, 
 
>          {NewYork, NewYork, UnitedStates}], 
 
>         Entity[City, {LosAngeles, California, UnitedStates}], 
 
>         Entity[City, {Chicago, Illinois, UnitedStates}]}, 
 
>        {EntityProperty[City, MedianHouseholdIncome], 
 
>         EntityProperty[City, PerCapitaIncome], 
 
>         EntityProperty[City, PopulationByPovertyStatus, 
 
>          {PovertyLevel -> Below, Percent -> Main}]}, 
 
>        PropertyEntityAssociation]]], 
 
>    {{EconomicProperties:CityData, 1}, Input} -> 
 
>     HoldComplete[Dataset[EntityValue[{Entity[City, 
 
>          {NewYork, NewYork, UnitedStates}], 
 
>         Entity[City, {LosAngeles, California, UnitedStates}], 
 
>         Entity[City, {Chicago, Illinois, UnitedStates}]}, 
 
>        {EntityProperty[City, UnemploymentRate], 
 
>         EntityProperty[City, TotalSalesTaxRate]}, PropertyEntityAssociation]]]
 
>     , {{QualityOfLife:CityData, 1}, Input} -> 
 
>     HoldComplete[Dataset[EntityValue[{Entity[City, 
 
>          {NewYork, NewYork, UnitedStates}], 
 
>         Entity[City, {LosAngeles, California, UnitedStates}], 
 
>         Entity[City, {Chicago, Illinois, UnitedStates}]}, 
 
>        {EntityProperty[City, DailyDelayMinutes]}, PropertyEntityAssociation]]]
 
>     , {{GeographicProperties:CityData, 1}, Input} -> 
 
>     HoldComplete[Dataset[EntityValue[{Entity[City, 
 
>          {NewYork, NewYork, UnitedStates}], 
 
>         Entity[City, {LosAngeles, California, UnitedStates}], 
 
>         Entity[City, {Chicago, Illinois, UnitedStates}]}, 
 
>        {EntityProperty[City, Elevation], EntityProperty[City, Area], 
 
>         EntityProperty[City, PopulationDensity]}, EntityPropertyAssociation]]]
 
>     }

アメリカ合衆国の三大都市における最終学歴

Dataset[EntityValue[{Entity["City", {"NewYork", "NewYork", "UnitedStates"}], Entity["City", {"LosAngeles", "California", "UnitedStates"}], Entity["City", {"Chicago", "Illinois", "UnitedStates"}]}, {EntityProperty["City", "PopulationByEducationalAttainment", {"EducationAttainmentRange" -> "Associate-Doctorate", "Percent" -> "Main"}], EntityProperty["City", "PopulationByEducationalAttainment", {"EducationAttainment" -> "HighSchool", "Percent" -> "Main"}], EntityProperty["City", "PopulationByEducationalAttainment", {"EducationAttainmentRange" -> "NoSchooling-Twelfth", "Percent" -> "Main"}]}, "PropertyEntityAssociation"]]
Output
{Entity["City", {"Chicago", "Illinois", "UnitedStates"}], Entity["City", {"Omaha", "Nebraska", "UnitedStates"}]}
Output
Table[city["Population"], {city, %}]
Output
SemanticInterpretation["Cat"]
Output
InputForm[%]
Entity["Species", "Species:FelisCatus"]
Entity["CatBreed", "Singapura"]
Output
EntityProperties[%]
Output
EntityValue[Entity["CatBreed", "Singapura"], "Image"]
Output