Wolfram 언어

텍스트와 언어 처리

자연 언어를 사용한 Wolfram Knowledgebase 쿼리 수행

아티스트 또는 앨범에서 노래를 검색하는 함수를 작성하고 작곡가의 정보 테이블을 생성합니다.

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}}}]}]]

임베디드 인터프리터를 이용하여 간단한 문법을 배치하여 "MusicAct" "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]=

관련 예제

de en es fr ja pt-br ru zh