I try to calculate the average length (in words) of paragraphs in a document. The data look like:
data=<|923 -> {"The food at snack is a selection of popular Greek dishes.
The appetizer tray is good as is the Greek salad. We were \=
underwhelmed with the main courses. There are 4-5 tables here so it's
sometimes hard to get seated."},
924 -> {"This little place in Soho is wonderful. I had a lamb
sandwich and a glass of wine. The price shocked me for how small the
serving was, but then again, this is Soho. The staff can be a little
snotty and rude, but the food is great, just don't expect world-class
service."},
925 -> {"ordered lunch for 15 from Snack last Friday. On time,
nothing missing and the food was great. I have added it to the
regular company lunch list, as everyone enjoyed their meal.",
"ordered lunch for 15 from Snack last Friday. On time, nothing
missing and the food was great. I have added it to the regular
company lunch list, as everyone enjoyed their meal."}|>
where keys are a number of documents and values are the paragraphs. I calculate the average length in words with the following function:
averegL[text_] := Module[{l = Length@text, res},
res = Total[WordCount[#] & /@ text]/l]
ParallelMap[averegL[#] &, data]; // AbsoluteTiming
Unfortunately, it takes a lot of time to calculate for all dataset (the dataset is ~ 300000 keys). I look for a way to speed up this calculation.
ExampleData[{"Text", "PrideAndPrejudice"}]; data = Association@MapIndexed[First@#2 -> # &, StringSplit[%, "."]];
(Sentences can serve as paragraphs for the purposes of computation, perhaps.) $\endgroup$