Abfrage der Wolfram Knowledgebase mit natürlicher Sprache
Erzeugen Sie eine Funktion, um ein Lied nach Interpret und Album nachzuschlagen. Generieren Sie eine Tabelle mit Information zum Komponisten.
In[1]:=
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}}}]}]]
Stellen Sie eine einfache Grammatik bereit, die eingebaute Interpreter zur Verwendung der Entitätstypen "MusicAct" und "MusicAlbum" verwendet.
In[2]:=
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]}]]
In[4]:=
GrammarApply[songGrammar, "tracks by Michael Jackson on Thriller"]
Out[4]=
In[5]:=
GrammarApply[songGrammar, "Pink Floyd's Dark Side of the Moon"]
Out[5]=