Wolfram Language

Text & Language Processing

Query the Wolfram Knowledgebase Using Natural Language

Create a function to look up songs by artist and album and generate a table with composer information.

In[1]:=
Click for copyable input
songLookup[act_, album_] := Module[{actEntity, albumEntity, songs, composers}, actEntity = Interpreter["MusicAct"][act]; albumEntity = Interpreter["MusicAlbum"][album]; songs = EntityList[ EntityClass[ "MusicWork", {"AssociatedMusicActs" -> actEntity, "AssociatedMusicAlbums" -> albumEntity}]]; composers = EntityValue[songs, "Composers"]; Column[{albumEntity["Image"], Grid[Transpose[{songs, composers}], Background -> {Automatic, {{LightOrange, White}}}]}]]

Deploy a simple grammar that utilizes built-in interpreters to recognize "MusicAct" and "MusicAlbum" entity types.

In[2]:=
Click for copyable input
songGrammar = CloudDeploy[ GrammarRules[ {AnyOrder[ OptionalElement[ FixedOrder[ "songs" | "titles" | "tracks" | "tunes" | "recordings", OptionalElement["by" | "from"]]], act : GrammarToken["MusicAct"], FixedOrder[OptionalElement["from" | "on"], album : GrammarToken["MusicAlbum"]] ] :> songLookup[act, album]}]]
Out[3]=
In[4]:=
Click for copyable input
GrammarApply[songGrammar, "tracks by Michael Jackson on Thriller"]
Out[4]=
In[5]:=
Click for copyable input
GrammarApply[songGrammar, "Pink Floyd's Dark Side of the Moon"]
Out[5]=

Related Examples

de es fr ja ko pt-br ru zh