Wolfram 언어

외부 서비스

H.G. 웰스의 우주 전쟁 (The War of the Worlds)에서 컨텍스트 명사의 그래프 생성

OpenLibrary API에 연결하여 "우주 전쟁"의 텍스트를 가져옵니다.

In[1]:=
Click for copyable input
ol = ServiceConnect["OpenLibrary"]; text = ol["BookText", "BibKeys" -> {{\[ThinSpace]"OLID", "OL7211749M"}\[ThinSpace]}];

화성인 침략자 관련 단어를 시각화하는 WordCloud를 생성합니다.

전체 Wolfram 언어 입력 표시하기
In[2]:=
Click for copyable input
sentences = TextSentences[text[1]]; preresult = DeleteCases[ Function[s, Module[{sentence = DeleteStopwords[TextWords[ToLowerCase[s]]]}, If[MemberQ[sentence, "martian" | "martians"], sentence] ]] /@ sentences, Null]; WordCloud[Tally[preresult]]
Out[2]=

그 컨텍스트에서 명사 그래프를 작성합니다.

전체 Wolfram 언어 입력 표시하기
In[3]:=
Click for copyable input
edges = Function[u, Module[{words = Pick[u, MemberQ[#, Entity["GrammaticalUnit", "Noun"]] & /@ (PartOfSpeech /@ u), True], basicedges, martianedges}, basicedges = UndirectedEdge @@@ Partition[words, 2, 1]; basicedges ]] /@ preresult; Graph[Flatten[edges], VertexStyle -> RGBColor[0.6, 0.12, 0.], EdgeStyle -> RGBColor[0.84, 0.04, 0.]]
Out[3]=

관련 예제