‹›External ServicesCreate a Graph of Contextual Nouns from H. G. Wells's The War of the Worlds
Connect to the OpenLibrary API to get The War of the Worlds book text.
ol = ServiceConnect["OpenLibrary"];
text = ol["BookText",
"BibKeys" -> {{\[ThinSpace]"OLID", "OL7211749M"}\[ThinSpace]}];
You can create a word cloud to visualize the words related to the Martian invaders.
show complete Wolfram Language 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]]
And create a graph of nouns in that context.
show complete Wolfram Language 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.]]