A novel Vanity Fair by William Thackeray has many different characters in it, such as Emmy Sedley, Becky Sharp, and Rawdon Crowley. Is it possible to use Mathematica to automatically count the number of the characters in the novel?
As another example, one could consider how to exactly count the approximately 600 characters in And Quiet Flows the Don by Mikhail Sholokhov.
Here is a link to the plain text.
Import["http://www.gutenberg.org/cache/epub/599/pg599.txt"]
str
, the number of characters can be given byStringLength[str]
. How to import the text is another question and I don't think questions such as "find a free version of this book for me" is in the scope of mma.se. edit I think I misunderstood character = person and character = element of a string. $\endgroup$t1 = StringSplit[ Import["http://www.gutenberg.org/cache/epub/599/pg599.txt"]]; p1 = Tally[ Select[Partition[t1, 2, 1], And @@ (StringLength[#1] > 2 && UpperCaseQ[StringTake[#1, 1]] &) /@ #1 &]]; p2 = Select[p1, DictionaryWordQ[#1[[1, 1]]] && DictionaryWordQ[#1[[1, 2]]] &]; p3 = Select[p2, LowerCaseQ[ StringTake[#1[[1, 1]], {2, 2}] <> StringTake[#1[[1, 2]], {2, 2}]] &]; p4 = (Reverse[SortBy[#1, Last]] &)[ Select[p4, StringMatchQ[StringJoin[#1[[1]]], __?LetterQ] &]]; Column@p4
$\endgroup$