{"id":316218,"date":"2021-01-12T03:00:53","date_gmt":"2021-01-12T03:00:53","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=316218"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=316218","title":{"rendered":"\u0421\u0442\u0438\u043b\u043e\u043c\u0435\u0442\u0440\u0438\u044f, \u0438\u043b\u0438 \u043a\u0430\u043a \u043e\u0442\u043b\u0438\u0447\u0438\u0442\u044c \u0410\u043a\u0443\u043d\u0438\u043d\u0430 \u043e\u0442 \u0411\u0443\u043b\u0433\u0430\u043a\u043e\u0432\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e 50 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430?"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440.<\/p>\n<p>\u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c &#171;\u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438&#187; \u0438 NLP (Natural Languages Processing \u0430 \u0432\u043e\u0432\u0441\u0435 \u043d\u0435 \u0442\u043e \u0447\u0442\u043e \u043c\u043d\u043e\u0433\u0438\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e\u0434\u0443\u043c\u0430\u043b\u0438) \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u0438\u0437 \u0442\u0435\u043a\u0441\u0442\u0430. \u041f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u044d\u0442\u043e \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u043e\u043b\u0433\u043e \u0434\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043e\u0432, \u0438 \u0438\u043c\u0435\u043b\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0446\u0435\u043b\u044c: \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0430 \u0442\u043e\u0433\u043e \u0438\u043b\u0438 \u0438\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u041f\u041a \u044d\u0442\u043e \u0432\u043f\u0440\u043e\u0447\u0435\u043c, \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0435\u0433\u0447\u0435 \u0438 \u0443\u0434\u043e\u0431\u043d\u0435\u0435, \u0434\u0430 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0432\u0435\u0441\u044c\u043c\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0430 Python.<\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0445 \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c.<\/p>\n<h2>\u0418\u0441\u0442\u043e\u0440\u0438\u044f<\/h2>\n<p>\u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043f\u0435\u0440\u0432\u044b\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u0431\u044b\u043b\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u0440\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432 <a href=\"https:\/\/en.wikipedia.org\/wiki\/The_Federalist_Papers\" rel=\"noopener noreferrer nofollow\">The&nbsp;Federalist Papers<\/a>, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0432 \u0421\u0428\u0410 \u0432 1780 \u0433\u043e\u0434\u0430\u0445. \u0418\u0445 \u0430\u0432\u0442\u043e\u0440\u0430\u043c\u0438 \u0431\u044b\u043b\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u043d\u043e \u043a\u0442\u043e \u0435\u0441\u0442\u044c \u043a\u0442\u043e, \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u043b\u043e \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e. \u041f\u0435\u0440\u0432\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u043a\u0440\u0438\u0432\u043e\u0439 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b \u0441\u043b\u043e\u0432 \u0431\u044b\u043b \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u043d\u044f\u0442 \u0435\u0449\u0435 <a href=\"https:\/\/www.historyofinformation.com\/detail.php?id=4120\" rel=\"noopener noreferrer nofollow\">\u0432 1851 \u0433<\/a>, \u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u044d\u0442\u043e \u0431\u044b\u043b \u043e\u0431\u044a\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u044b. \u0421\u0435\u0439\u0447\u0430\u0441, \u0441\u043b\u0430\u0432\u0430 \u0431\u043e\u0433\u0443, \u0432\u0441\u0451 \u043f\u0440\u043e\u0449\u0435. \u042f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u0432 \u0438 \u043f\u0430\u043a\u0435\u0442\u0430 <a href=\"https:\/\/www.nltk.org\" rel=\"noopener noreferrer nofollow\">Natural Language Toolkit<\/a>, \u0447\u0442\u043e \u0432 \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u0438 \u0441 matplotlib \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430. \u041c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0432\u0441\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0438 \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c. <\/p>\n<p>\u0422\u0435, \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u0433\u043b\u0430\u0432\u0443 &#171;\u043a\u043e\u0434&#187; \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c.<\/p>\n<h2>\u041a\u043e\u0434<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443. \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u0435\u043a\u0441\u0442:<\/p>\n<pre><code class=\"python\">s = \"\"\"\u0415\u0436\u0438\u043a \u0441\u0438\u0434\u0435\u043b  \u043d\u0430 \u0433\u043e\u0440\u043a\u0435 \u043f\u043e\u0434  \u0441\u043e\u0441\u043d\u043e\u0439 \u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u043b \u043d\u0430 \u043e\u0441\u0432\u0435\u0449\u0435\u043d\u043d\u0443\u044e         \u043b\u0443\u043d\u043d\u044b\u043c \u0441\u0432\u0435\u0442\u043e\u043c \u0434\u043e\u043b\u0438\u043d\u0443, \u0437\u0430\u0442\u043e\u043f\u043b\u0435\u043d\u043d\u0443\u044e \u0442\u0443\u043c\u0430\u043d\u043e\u043c. \u041a\u0440\u0430\u0441\u0438\u0432\u043e \u0431\u044b\u043b\u043e \u0442\u0430\u043a, \u0447\u0442\u043e         \u043e\u043d \u0432\u0440\u0435\u043c\u044f \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u0437\u0434\u0440\u0430\u0433\u0438\u0432\u0430\u043b: \u043d\u0435 \u0441\u043d\u0438\u0442\u0441\u044f \u043b\u0438 \u0435\u043c\u0443 \u0432\u0441\u0435 \u044d\u0442\u043e?\"\"\"<\/code><\/pre>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 nltk:<\/p>\n<pre><code class=\"python\">import nltk  nltk.data.find('tokenizers\/punkt')  tokens = nltk.word_tokenize(s)<\/code><\/pre>\n<p>\u041c\u0430\u0441\u0441\u0438\u0432 tokens \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u0441\u043b\u043e\u0432\u0430 \u0438 \u0437\u043d\u0430\u043a\u0438 \u043f\u0443\u043d\u043a\u0442\u0443\u0430\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"bash\">['\u0415\u0436\u0438\u043a', '\u0441\u0438\u0434\u0435\u043b', '\u043d\u0430', '\u0433\u043e\u0440\u043a\u0435', '\u043f\u043e\u0434', '\u0441\u043e\u0441\u043d\u043e\u0439', '\u0438', '\u0441\u043c\u043e\u0442\u0440\u0435\u043b', '\u043d\u0430',   '\u043e\u0441\u0432\u0435\u0449\u0435\u043d\u043d\u0443\u044e', '\u043b\u0443\u043d\u043d\u044b\u043c', '\u0441\u0432\u0435\u0442\u043e\u043c', '\u0434\u043e\u043b\u0438\u043d\u0443', ',', '\u0437\u0430\u0442\u043e\u043f\u043b\u0435\u043d\u043d\u0443\u044e', '\u0442\u0443\u043c\u0430\u043d\u043e\u043c', '.'   ...]<\/code><\/pre>\n<p>\u041e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432, \u0443\u0434\u0430\u043b\u0438\u0432 \u0438\u0437 \u043d\u0435\u0433\u043e \u0437\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u043f\u0438\u043d\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">import string  remove_punctuation = str.maketrans('', '', string.punctuation) tokens_ = [x for x in [t.translate(remove_punctuation).lower() for t in tokens] if len(x) &gt; 0]<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440: <strong>\u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430<\/strong>. \u042d\u0442\u043e \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u043b\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u043a \u0438\u0445 \u043e\u0431\u0449\u0435\u043c\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443.<\/p>\n<pre><code class=\"python\">text = nltk.Text(tokens_) lexical_divercity = (len(set(text)) \/ len(text)) * 100<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u044d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0440\u0430\u0432\u0435\u043d 96.6%.<\/p>\n<p>\u041d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <strong>\u0441\u0440\u0435\u0434\u043d\u044e\u044e \u0434\u043b\u0438\u043d\u0443 \u0441\u043b\u043e\u0432\u0430<\/strong>:<\/p>\n<pre><code class=\"python\">words = set(tokens_) word_chars = [len(word) for word in words] mean_word_len = sum(word_chars) \/ float(len(word_chars))<\/code><\/pre>\n<p>\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e set(tokens_) \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u043d\u0435\u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0439\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043b\u043e\u0432, \u0434\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0441\u0440\u0435\u0434\u043d\u0435\u0435, \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0432 \u0441\u0443\u043c\u043c\u0443 \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u043b\u043e\u0432\u0430 \u0440\u0430\u0432\u043d\u0430 4.86.<\/p>\n<p><strong>\u0421\u0440\u0435\u0434\u043d\u044f\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438<\/strong>\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <em>sent_tokenize<\/em> \u0432 NLTK, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043a\u0430\u043a \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"python\">import numpy as np sentences = nltk.sent_tokenize(s) sentence_word_length = [len(sent.split()) for sent in sentences] mean_sentence_len = np.mean(sentence_word_length)<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u0434\u043b\u0438\u043d\u0430 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 15 \u0441\u043b\u043e\u0432.<\/p>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 &#8212; <strong>\u0447\u0430\u0441\u0442\u043e\u0442\u043d\u043e\u0441\u0442\u044c <\/strong>\u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0438\u043c\u043e\u043b\u043e\u0432. \u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u0442\u0438\u043b\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u044f\u0442\u044b\u0445, \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043a\u0430\u0432\u044b\u0447\u0435\u043a, \u0440\u0430\u0437\u043d\u044b\u0445 \u043d\u0435\u0441\u043a\u043b\u043e\u043d\u044f\u0435\u043c\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u0440\u0435\u0447\u0438 (&#171;\u0447\u0442\u043e&#187;, &#171;\u0432&#187;). \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u044f\u0442\u044b\u0445 \u043d\u0430 1000 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0442\u0435\u043a\u0441\u0442\u0430:<\/p>\n<pre><code class=\"python\">fdist = nltk.probability.FreqDist(nltk.Text(tokens)) commas_per_thousand = (fdist[\",\"] * 1000) \/ fdist.N()<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 57.14 \u0437\u0430\u043f\u044f\u0442\u044b\u0445 \u043d\u0430 1000 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c &#8212; \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430.<\/p>\n<pre><code class=\"python\">import codecs  try:     doc = codecs.open(file_name, 'r', 'cp1251').read() except:     doc = codecs.open(file_name, 'r', 'utf-8').read()<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430. \u0427\u0430\u0441\u0442\u044c \u0444\u0430\u0439\u043b\u043e\u0432, \u0441\u043a\u0430\u0447\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043e\u043d\u043b\u0430\u0439\u043d-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435 1251. \u0414\u0440\u0443\u0433\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0444\u0430\u0439\u043b\u043e\u0432 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u043c copy-paste \u0432 \u0411\u043b\u043e\u043a\u043d\u043e\u0442\u0435, \u0438 \u0438\u043c\u0435\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443 UTF-8. \u0412\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0444\u0430\u0439\u043b \u043a\u0430\u043a 1251, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u0438 \u043c\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0447\u0442\u043e \u044d\u0442\u043e UTF-8, \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0432\u043f\u043e\u043b\u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e.<\/p>\n<h2>\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>\u041f\u043e\u043a\u0430 \u0432\u0441\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043a\u0443\u0447\u043d\u043e. \u0413\u043e\u0440\u0430\u0437\u0434\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438. \u042f \u0432\u0437\u044f\u043b \u043d\u0430\u0443\u0433\u0430\u0434 \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u043a\u043d\u0438\u0433\u0435 \u043e\u0442 4\u0445 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0430\u0432\u0442\u043e\u0440\u043e\u0432, \u0442\u0435\u043a\u0441\u0442\u044b \u0431\u044b\u043b\u0438 \u0432\u0437\u044f\u0442\u044b \u0441\u043e \u0432\u0441\u0435\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u041c\u0430\u043a\u0441\u0438\u043c\u0430 \u041c\u043e\u0448\u043a\u043e\u0432\u0430 Lib.ru.  \u041a\u0430\u0436\u0434\u0430\u044f \u043a\u043d\u0438\u0433\u0430 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0431\u043b\u043e\u043a\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0439 \u0434\u043b\u0438\u043d\u044b, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c.<\/p>\n<p>\u041b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u0435 \u0438 \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u043b\u043e\u0432\u0430 \u043d\u0435 \u0434\u0430\u044e\u0442 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0437\u0430\u043c\u0435\u0442\u043d\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/te\/ms\/wx\/temswxggbjre_wosu1yh-yhmsp0.png\" width=\"1476\" height=\"574\"><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0432\u0441\u0435 \u0430\u0432\u0442\u043e\u0440\u044b \u043b\u044e\u0434\u0438 \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435, \u0442\u0435\u043a\u0441\u0442\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u0438 \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u043d\u044b\u043c \u0440\u0443\u0441\u0441\u043a\u0438\u043c \u044f\u0437\u044b\u043a\u043e\u043c, \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u0432 \u043e\u0431\u044a\u0435\u043c\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0441\u043b\u043e\u0432 \u043d\u0435 \u0432\u0438\u0434\u043d\u043e. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 &#171;\u0434\u043b\u0438\u043d\u0430 \u0441\u043b\u043e\u0432\u0430&#187; \u0442\u043e\u0436\u0435 \u043d\u0435 \u0434\u0430\u0435\u0442 \u0432\u0438\u0434\u0438\u043c\u044b\u0445 \u043e\u0442\u043b\u0438\u0447\u0438\u0439. \u0410 \u0432\u043e\u0442 \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u0435\u0441\u044c\u043c\u0430 \u0437\u0430\u043c\u0435\u0442\u043d\u043e:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/sb\/ms\/gn\/sbmsgn2qyzus3mfpv_jgok_1xei.png\" width=\"1474\" height=\"573\"><figcaption><\/figcaption><\/figure>\n<p>\u0423 \u041d\u0430\u0431\u043e\u043a\u043e\u0432\u0430 \u0441\u0442\u0438\u043b\u044c, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f, \u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u0430. \u042d\u0442\u043e \u043d\u0435\u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e &#8212; \u0435\u0441\u043b\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0441\u0430\u043c\u0443 \u043a\u043d\u0438\u0433\u0443, \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0442\u0430\u043a\u0438\u0445:<\/p>\n<p><em>\u041e\u043d \u0431\u043e\u044f\u043b\u0441\u044f, \u041b\u0443\u0436\u0438\u043d \u0441\u0442\u0430\u0440\u0448\u0438\u0439, \u0447\u0442\u043e, \u043a\u043e\u0433\u0434\u0430 \u0441\u044b\u043d \u0443\u0437\u043d\u0430\u0435\u0442, \u0437\u0430\u0447\u0435\u043c \u0442\u0430\u043a \u043d\u0443\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0431\u0435\u0437\u043b\u0438\u043a\u0438\u0435 \u0422\u0440\u0443\u0432\u043e\u0440 \u0438 \u0421\u0438\u043d\u0435\u0443\u0441, \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043b\u043e\u0432, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0445 \u044f\u0442\u044c, \u0438 \u0433\u043b\u0430\u0432\u043d\u0435\u0439\u0448\u0438\u0435 \u0440\u0443\u0441\u0441\u043a\u0438\u0435 \u0440\u0435\u043a\u0438, \u0441 \u043d\u0438\u043c \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0442\u043e \u0436\u0435, \u0447\u0442\u043e \u0434\u0432\u0430   \u0433\u043e\u0434\u0430  \u043d\u0430\u0437\u0430\u0434,  \u043a\u043e\u0433\u0434\u0430,  \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e  \u0438  \u0442\u044f\u0436\u043a\u043e,  \u043f\u0440\u0438  \u0437\u0432\u0443\u043a\u0435 \u0441\u043a\u0440\u0438\u043f\u0435\u0432\u0448\u0438\u0445   \u0441\u0442\u0443\u043f\u0435\u043d\u0435\u0439,   \u0441\u0442\u0440\u0435\u043b\u044f\u0432\u0448\u0438\u0445   \u043f\u043e\u043b\u043e\u0432\u0438\u0446,    \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0433\u0430\u0435\u043c\u044b\u0445 \u0441\u0443\u043d\u0434\u0443\u043a\u043e\u0432,  \u043d\u0430\u043f\u043e\u043b\u043d\u0438\u0432  \u0441\u043e\u0431\u043e\u044e  \u0432\u0435\u0441\u044c \u0434\u043e\u043c, \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0444\u0440\u0430\u043d\u0446\u0443\u0436\u0435\u043d\u043a\u0430.<\/em><\/p>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u044f\u0442\u044b\u0445 \u043d\u0430 1000 \u0441\u043b\u043e\u0432 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f, \u0438 \u044d\u0442\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e &#8212; \u0432 \u0434\u043b\u0438\u043d\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0438\u0445, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0438 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/lk\/x9\/l5\/lkx9l5mbackw9i9ag1k06wdyxhe.png\" width=\"1466\" height=\"571\"><figcaption><\/figcaption><\/figure>\n<p>\u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0430\u043d\u0430\u043b\u0438\u0437 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e \u043b\u044e\u0431\u043e\u043c\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c, \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u0443 \u0440\u0430\u0437\u043d\u044b\u0445 \u0430\u0432\u0442\u043e\u0440\u043e\u0432 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u043a \u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u044f &#171;:&#187;:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/1z\/gn\/43\/1zgn43zgqmhvdzrjjqo_ue1ad_c.png\" width=\"1479\" height=\"575\"><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0434\u0435\u044f, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043f\u043e\u043d\u044f\u0442\u043d\u0430. &#171;\u041e\u0442\u043f\u0435\u0447\u0430\u0442\u043e\u043a&#187; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0430\u0432\u0442\u043e\u0440\u043e\u0432, \u0438 \u043a\u0430\u043a <a href=\"https:\/\/towardsdatascience.com\/using-nlp-to-identify-redditors-who-control-multiple-accounts-837483c8b782\" rel=\"noopener noreferrer nofollow\">\u0431\u044b\u043b\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e<\/a>, \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u0436\u0435 \u0434\u043b\u044f \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u043e\u043d\u043e\u0432 \u043d\u0430 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u043c \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u043c \u0441\u0430\u0439\u0442\u0435. \u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e \u0434\u043b\u044f \u0440\u0443\u0441\u0441\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430, \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e.<\/p>\n<p>\u041c\u044b \u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u043f\u0440\u043e\u0449\u0435. \u041f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0432 \u0421\u0421\u0421\u0420 \u0434\u0435\u0442\u0441\u043a\u0430\u044f \u043a\u043d\u0438\u0433\u0430 &#171;\u0423\u043b\u0438\u0446\u0430 \u043c\u043b\u0430\u0434\u0448\u0435\u0433\u043e \u0441\u044b\u043d\u0430&#187; \u0438\u043c\u0435\u0435\u0442 \u0434\u0432\u0443\u0445 \u0430\u0432\u0442\u043e\u0440\u043e\u0432, \u041b\u0435\u0432 \u041a\u0430\u0441\u0441\u0438\u043b\u044c \u0438 \u041c\u0430\u043a\u0441 \u041f\u043e\u043b\u044f\u043d\u043e\u0432\u0441\u043a\u0438\u0439. \u041d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u043f\u043e Lexical Diversity. \u041c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0447\u0442\u043e \u043d\u0430\u0447\u0430\u043b\u043e \u043a\u043d\u0438\u0433\u0438 \u043f\u0438\u0441\u0430\u043b \u043e\u0434\u0438\u043d \u0430\u0432\u0442\u043e\u0440, \u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b \u0434\u0440\u0443\u0433\u043e\u0439:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/l0\/ds\/be\/l0dsbetj4-qzzsr4lcq6uc6yxha.png\" width=\"1475\" height=\"570\"><figcaption><\/figcaption><\/figure>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439, \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u0433\u0440\u0430\u0444\u0438\u043a \u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u044f \u0434\u043b\u044f 10 \u043a\u043d\u0438\u0433 \u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u0434\u0430\u043c\u0441\u043a\u043e\u0439 \u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c\u043d\u0438\u0446\u044b, \u0447\u044c\u0438 \u043a\u043d\u0438\u0433\u0438 \u043e\u0434\u043d\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0434\u0430\u0432\u0430\u043b\u0438\u0441\u044c \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435. \u0415\u0449\u0451 \u0442\u043e\u0433\u0434\u0430 \u044f \u0443\u0434\u0438\u0432\u043b\u044f\u043b\u0441\u044f, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c <em>\u0441\u0442\u043e\u043b\u044c\u043a\u043e<\/em> \u043a\u043d\u0438\u0433 \u0432 \u0442\u0430\u043a\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435. \u041e\u0442\u0432\u0435\u0442 \u043b\u0438\u0447\u043d\u043e \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u0441\u0442\u0430\u043b \u043e\u0447\u0435\u0432\u0438\u0434\u0435\u043d, \u043d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e \u0432\u0438\u0434\u043d\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u044f &#8212; \u0441\u0442\u0438\u043b\u044c \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u043e\u0434\u043d\u043e\u0439 \u043a\u043d\u0438\u0433\u0438 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/n7\/tm\/y4\/n7tmy4nabyuj7i0nsvloycc0u10.png\" width=\"1476\" height=\"576\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u043c\u043e\u0436\u0435\u0442 \u044d\u0442\u043e \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435, \u0442\u0435\u043e\u0440\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0442\u0430\u043a\u043e\u0435, \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442&#8230;<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u044b\u0435, \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0448\u043a\u043e\u043b\u044c\u043d\u044b\u0435, \u0444\u043e\u0440\u043c\u0443\u043b\u044b, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b.<\/p>\n<p>\u0414\u043b\u044f \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0445 \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f Python 3.7 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u043e\u0434 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u043e\u043c.<\/p>\n<details class=\"spoiler\">\n<summary>text_process.py<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import nltk, codecs import numpy as np import pandas as pd import matplotlib.pyplot as plt from typing import Optional, List import string import glob import sys, os   def get_articles_from_blob(folder: str):     data = []     for path in glob.glob(folder + os.sep + \"*\"):         print(path)         data += get_articles_from_folder(path)     return data  def get_articles_from_folder(folder: str):     data = []     for path in glob.glob(folder + os.sep + \"*.txt\"):         data += get_data_from_file(path)     return [(folder.split(os.sep)[-1], data)]  def get_data_from_file(file_name: str):     print(\"Get data for %s\" % file_name)     try:         doc = codecs.open(file_name, 'r', 'cp1251').read()     except:         doc = codecs.open(file_name, 'r', 'utf-8').read()     chunk_size = 25000     data = []     for part in [doc[i:i+chunk_size] for i in range(0, len(doc) - (len(doc) % chunk_size), chunk_size)]:         data.append(get_data_from_str(part[part.find(' '):part.rfind(' ')]))     return data  def get_data_from_str(doc: str):     tokens = nltk.word_tokenize(doc)     remove_punctuation = str.maketrans('', '', string.punctuation)     tokens_ = [x for x in [t.translate(remove_punctuation).lower() for t in tokens] if len(x) &gt; 0]     text = nltk.Text(tokens_)     lexical_divercity = (len(set(text)) \/ len(text)) * 100      words = set(tokens_)     word_chars = [len(word) for word in words]     mean_word_len = sum(word_chars) \/ float(len(word_chars))      sentences = nltk.sent_tokenize(doc)     sentence_word_length = [len(sent.split()) for sent in sentences]     mean_sentence_len = np.mean(sentence_word_length)      fdist = nltk.probability.FreqDist(nltk.Text(tokens))     commas_per_thousand = (fdist[\",\"] * 1000) \/ fdist.N()     return (lexical_divercity, mean_word_len, mean_sentence_len, commas_per_thousand)   def plot_data(data):     plt.rcParams[\"figure.figsize\"] = (12, 5)     fig, ax = plt.subplots()      plt.title('Lexical diversity')     for author, author_data in data:         plt.plot(list(map(lambda val: val[0], author_data)), label=author)     plt.ylim([40, 70])      # plt.title('Mean Word Length')     # for author, author_data in data:     #     plt.plot(list(map(lambda val: val[1], author_data)), label=author)     # plt.ylim([4, 8])      # plt.title('Mean Sentence Length')     # for author, author_data in data:     #     plt.plot(list(map(lambda val: val[2], author_data)), label=author)     # plt.ylim([0, 30])      # plt.title(\"Commas per thousand\")     # for author, author_data in data:     #     plt.plot(list(map(lambda val: val[3], author_data)), label=author)      plt.legend(loc='upper right')     plt.tight_layout()     plt.show()   if __name__ == \"__main__\":     # Download punkt tokenizer     try:         nltk.data.find('tokenizers\/punkt')     except LookupError:         nltk.download('punkt')      # Process text files     # data = get_articles_from_blob(\"Folder\")  # Folder\/AuthorXX\/Text.txt     data = get_articles_from_folder(\"folder_here\")  # Folder with files     plot_data(data)<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/536858\/\"> https:\/\/habr.com\/ru\/post\/536858\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440.<\/p>\n<p>\u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c &#171;\u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438&#187; \u0438 NLP (Natural Languages Processing \u0430 \u0432\u043e\u0432\u0441\u0435 \u043d\u0435 \u0442\u043e \u0447\u0442\u043e \u043c\u043d\u043e\u0433\u0438\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e\u0434\u0443\u043c\u0430\u043b\u0438) \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u0438\u0437 \u0442\u0435\u043a\u0441\u0442\u0430. \u041f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u044d\u0442\u043e \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u043e\u043b\u0433\u043e \u0434\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043e\u0432, \u0438 \u0438\u043c\u0435\u043b\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0446\u0435\u043b\u044c: \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0430 \u0442\u043e\u0433\u043e \u0438\u043b\u0438 \u0438\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u041f\u041a \u044d\u0442\u043e \u0432\u043f\u0440\u043e\u0447\u0435\u043c, \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0435\u0433\u0447\u0435 \u0438 \u0443\u0434\u043e\u0431\u043d\u0435\u0435, \u0434\u0430 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0432\u0435\u0441\u044c\u043c\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0430 Python.<\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0445 \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c.<\/p>\n<h2>\u0418\u0441\u0442\u043e\u0440\u0438\u044f<\/h2>\n<p>\u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043f\u0435\u0440\u0432\u044b\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u0431\u044b\u043b\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u0440\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432 <a href=\"https:\/\/en.wikipedia.org\/wiki\/The_Federalist_Papers\" rel=\"noopener noreferrer nofollow\">The&nbsp;Federalist Papers<\/a>, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0432 \u0421\u0428\u0410 \u0432 1780 \u0433\u043e\u0434\u0430\u0445. \u0418\u0445 \u0430\u0432\u0442\u043e\u0440\u0430\u043c\u0438 \u0431\u044b\u043b\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u043d\u043e \u043a\u0442\u043e \u0435\u0441\u0442\u044c \u043a\u0442\u043e, \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u043b\u043e \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e. \u041f\u0435\u0440\u0432\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u043a\u0440\u0438\u0432\u043e\u0439 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b \u0441\u043b\u043e\u0432 \u0431\u044b\u043b \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u043d\u044f\u0442 \u0435\u0449\u0435 <a href=\"https:\/\/www.historyofinformation.com\/detail.php?id=4120\" rel=\"noopener noreferrer nofollow\">\u0432 1851 \u0433<\/a>, \u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u044d\u0442\u043e \u0431\u044b\u043b \u043e\u0431\u044a\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u044b. \u0421\u0435\u0439\u0447\u0430\u0441, \u0441\u043b\u0430\u0432\u0430 \u0431\u043e\u0433\u0443, \u0432\u0441\u0451 \u043f\u0440\u043e\u0449\u0435. \u042f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u0432 \u0438 \u043f\u0430\u043a\u0435\u0442\u0430 <a href=\"https:\/\/www.nltk.org\" rel=\"noopener noreferrer nofollow\">Natural Language Toolkit<\/a>, \u0447\u0442\u043e \u0432 \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u0438 \u0441 matplotlib \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430. \u041c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0432\u0441\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0438 \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c. <\/p>\n<p>\u0422\u0435, \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u0433\u043b\u0430\u0432\u0443 &#171;\u043a\u043e\u0434&#187; \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c.<\/p>\n<h2>\u041a\u043e\u0434<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443. \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u0435\u043a\u0441\u0442:<\/p>\n<pre><code class=\"python\">s = \"\"\"\u0415\u0436\u0438\u043a \u0441\u0438\u0434\u0435\u043b  \u043d\u0430 \u0433\u043e\u0440\u043a\u0435 \u043f\u043e\u0434  \u0441\u043e\u0441\u043d\u043e\u0439 \u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u043b \u043d\u0430 \u043e\u0441\u0432\u0435\u0449\u0435\u043d\u043d\u0443\u044e         \u043b\u0443\u043d\u043d\u044b\u043c \u0441\u0432\u0435\u0442\u043e\u043c \u0434\u043e\u043b\u0438\u043d\u0443, \u0437\u0430\u0442\u043e\u043f\u043b\u0435\u043d\u043d\u0443\u044e \u0442\u0443\u043c\u0430\u043d\u043e\u043c. \u041a\u0440\u0430\u0441\u0438\u0432\u043e \u0431\u044b\u043b\u043e \u0442\u0430\u043a, \u0447\u0442\u043e         \u043e\u043d \u0432\u0440\u0435\u043c\u044f \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u0437\u0434\u0440\u0430\u0433\u0438\u0432\u0430\u043b: \u043d\u0435 \u0441\u043d\u0438\u0442\u0441\u044f \u043b\u0438 \u0435\u043c\u0443 \u0432\u0441\u0435 \u044d\u0442\u043e?\"\"\"<\/code><\/pre>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 nltk:<\/p>\n<pre><code class=\"python\">import nltk  nltk.data.find('tokenizers\/punkt')  tokens = nltk.word_tokenize(s)<\/code><\/pre>\n<p>\u041c\u0430\u0441\u0441\u0438\u0432 tokens \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u0441\u043b\u043e\u0432\u0430 \u0438 \u0437\u043d\u0430\u043a\u0438 \u043f\u0443\u043d\u043a\u0442\u0443\u0430\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"bash\">['\u0415\u0436\u0438\u043a', '\u0441\u0438\u0434\u0435\u043b', '\u043d\u0430', '\u0433\u043e\u0440\u043a\u0435', '\u043f\u043e\u0434', '\u0441\u043e\u0441\u043d\u043e\u0439', '\u0438', '\u0441\u043c\u043e\u0442\u0440\u0435\u043b', '\u043d\u0430',   '\u043e\u0441\u0432\u0435\u0449\u0435\u043d\u043d\u0443\u044e', '\u043b\u0443\u043d\u043d\u044b\u043c', '\u0441\u0432\u0435\u0442\u043e\u043c', '\u0434\u043e\u043b\u0438\u043d\u0443', ',', '\u0437\u0430\u0442\u043e\u043f\u043b\u0435\u043d\u043d\u0443\u044e', '\u0442\u0443\u043c\u0430\u043d\u043e\u043c', '.'   ...]<\/code><\/pre>\n<p>\u041e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432, \u0443\u0434\u0430\u043b\u0438\u0432 \u0438\u0437 \u043d\u0435\u0433\u043e \u0437\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u043f\u0438\u043d\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">import string  remove_punctuation = str.maketrans('', '', string.punctuation) tokens_ = [x for x in [t.translate(remove_punctuation).lower() for t in tokens] if len(x) &gt; 0]<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440: <strong>\u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430<\/strong>. \u042d\u0442\u043e \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u043b\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u043a \u0438\u0445 \u043e\u0431\u0449\u0435\u043c\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443.<\/p>\n<pre><code class=\"python\">text = nltk.Text(tokens_) lexical_divercity = (len(set(text)) \/ len(text)) * 100<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u044d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0440\u0430\u0432\u0435\u043d 96.6%.<\/p>\n<p>\u041d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <strong>\u0441\u0440\u0435\u0434\u043d\u044e\u044e \u0434\u043b\u0438\u043d\u0443 \u0441\u043b\u043e\u0432\u0430<\/strong>:<\/p>\n<pre><code class=\"python\">words = set(tokens_) word_chars = [len(word) for word in words] mean_word_len = sum(word_chars) \/ float(len(word_chars))<\/code><\/pre>\n<p>\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e set(tokens_) \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u043d\u0435\u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0439\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043b\u043e\u0432, \u0434\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0441\u0440\u0435\u0434\u043d\u0435\u0435, \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0432 \u0441\u0443\u043c\u043c\u0443 \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u043b\u043e\u0432\u0430 \u0440\u0430\u0432\u043d\u0430 4.86.<\/p>\n<p><strong>\u0421\u0440\u0435\u0434\u043d\u044f\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438<\/strong>\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <em>sent_tokenize<\/em> \u0432 NLTK, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043a\u0430\u043a \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"python\">import numpy as np sentences = nltk.sent_tokenize(s) sentence_word_length = [len(sent.split()) for sent in sentences] mean_sentence_len = np.mean(sentence_word_length)<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u0434\u043b\u0438\u043d\u0430 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 15 \u0441\u043b\u043e\u0432.<\/p>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 &#8212; <strong>\u0447\u0430\u0441\u0442\u043e\u0442\u043d\u043e\u0441\u0442\u044c <\/strong>\u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0438\u043c\u043e\u043b\u043e\u0432. \u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u0442\u0438\u043b\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u044f\u0442\u044b\u0445, \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043a\u0430\u0432\u044b\u0447\u0435\u043a, \u0440\u0430\u0437\u043d\u044b\u0445 \u043d\u0435\u0441\u043a\u043b\u043e\u043d\u044f\u0435\u043c\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u0440\u0435\u0447\u0438 (&#171;\u0447\u0442\u043e&#187;, &#171;\u0432&#187;). \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u044f\u0442\u044b\u0445 \u043d\u0430 1000 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0442\u0435\u043a\u0441\u0442\u0430:<\/p>\n<pre><code class=\"python\">fdist = nltk.probability.FreqDist(nltk.Text(tokens)) commas_per_thousand = (fdist[\",\"] * 1000) \/ fdist.N()<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 57.14 \u0437\u0430\u043f\u044f\u0442\u044b\u0445 \u043d\u0430 1000 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c &#8212; \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430.<\/p>\n<pre><code class=\"python\">import codecs  try:     doc = codecs.open(file_name, 'r', 'cp1251').read() except:     doc = codecs.open(file_name, 'r', 'utf-8').read()<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430. \u0427\u0430\u0441\u0442\u044c \u0444\u0430\u0439\u043b\u043e\u0432, \u0441\u043a\u0430\u0447\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043e\u043d\u043b\u0430\u0439\u043d-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435 1251. \u0414\u0440\u0443\u0433\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0444\u0430\u0439\u043b\u043e\u0432 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u043c copy-paste \u0432 \u0411\u043b\u043e\u043a\u043d\u043e\u0442\u0435, \u0438 \u0438\u043c\u0435\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443 UTF-8. \u0412\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0444\u0430\u0439\u043b \u043a\u0430\u043a 1251, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u0438 \u043c\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0447\u0442\u043e \u044d\u0442\u043e UTF-8, \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0432\u043f\u043e\u043b\u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e.<\/p>\n<h2>\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>\u041f\u043e\u043a\u0430 \u0432\u0441\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043a\u0443\u0447\u043d\u043e. \u0413\u043e\u0440\u0430\u0437\u0434\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438. \u042f \u0432\u0437\u044f\u043b \u043d\u0430\u0443\u0433\u0430\u0434 \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u043a\u043d\u0438\u0433\u0435 \u043e\u0442 4\u0445 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0430\u0432\u0442\u043e\u0440\u043e\u0432, \u0442\u0435\u043a\u0441\u0442\u044b \u0431\u044b\u043b\u0438 \u0432\u0437\u044f\u0442\u044b \u0441\u043e \u0432\u0441\u0435\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u041c\u0430\u043a\u0441\u0438\u043c\u0430 \u041c\u043e\u0448\u043a\u043e\u0432\u0430 Lib.ru.  \u041a\u0430\u0436\u0434\u0430\u044f \u043a\u043d\u0438\u0433\u0430 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0431\u043b\u043e\u043a\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0439 \u0434\u043b\u0438\u043d\u044b, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c.<\/p>\n<p>\u041b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u0435 \u0438 \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u043b\u043e\u0432\u0430 \u043d\u0435 \u0434\u0430\u044e\u0442 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0437\u0430\u043c\u0435\u0442\u043d\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0432\u0441\u0435 \u0430\u0432\u0442\u043e\u0440\u044b \u043b\u044e\u0434\u0438 \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435, \u0442\u0435\u043a\u0441\u0442\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u0438 \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u043d\u044b\u043c \u0440\u0443\u0441\u0441\u043a\u0438\u043c \u044f\u0437\u044b\u043a\u043e\u043c, \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u0432 \u043e\u0431\u044a\u0435\u043c\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0441\u043b\u043e\u0432 \u043d\u0435 \u0432\u0438\u0434\u043d\u043e. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 &#171;\u0434\u043b\u0438\u043d\u0430 \u0441\u043b\u043e\u0432\u0430&#187; \u0442\u043e\u0436\u0435 \u043d\u0435 \u0434\u0430\u0435\u0442 \u0432\u0438\u0434\u0438\u043c\u044b\u0445 \u043e\u0442\u043b\u0438\u0447\u0438\u0439. \u0410 \u0432\u043e\u0442 \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u0435\u0441\u044c\u043c\u0430 \u0437\u0430\u043c\u0435\u0442\u043d\u043e:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0423 \u041d\u0430\u0431\u043e\u043a\u043e\u0432\u0430 \u0441\u0442\u0438\u043b\u044c, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f, \u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u0430. \u042d\u0442\u043e \u043d\u0435\u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e &#8212; \u0435\u0441\u043b\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0441\u0430\u043c\u0443 \u043a\u043d\u0438\u0433\u0443, \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0442\u0430\u043a\u0438\u0445:<\/p>\n<p><em>\u041e\u043d \u0431\u043e\u044f\u043b\u0441\u044f, \u041b\u0443\u0436\u0438\u043d \u0441\u0442\u0430\u0440\u0448\u0438\u0439, \u0447\u0442\u043e, \u043a\u043e\u0433\u0434\u0430 \u0441\u044b\u043d \u0443\u0437\u043d\u0430\u0435\u0442, \u0437\u0430\u0447\u0435\u043c \u0442\u0430\u043a \u043d\u0443\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0431\u0435\u0437\u043b\u0438\u043a\u0438\u0435 \u0422\u0440\u0443\u0432\u043e\u0440 \u0438 \u0421\u0438\u043d\u0435\u0443\u0441, \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043b\u043e\u0432, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0445 \u044f\u0442\u044c, \u0438 \u0433\u043b\u0430\u0432\u043d\u0435\u0439\u0448\u0438\u0435 \u0440\u0443\u0441\u0441\u043a\u0438\u0435 \u0440\u0435\u043a\u0438, \u0441 \u043d\u0438\u043c \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0442\u043e \u0436\u0435, \u0447\u0442\u043e \u0434\u0432\u0430   \u0433\u043e\u0434\u0430  \u043d\u0430\u0437\u0430\u0434,  \u043a\u043e\u0433\u0434\u0430,  \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e  \u0438  \u0442\u044f\u0436\u043a\u043e,  \u043f\u0440\u0438  \u0437\u0432\u0443\u043a\u0435 \u0441\u043a\u0440\u0438\u043f\u0435\u0432\u0448\u0438\u0445   \u0441\u0442\u0443\u043f\u0435\u043d\u0435\u0439,   \u0441\u0442\u0440\u0435\u043b\u044f\u0432\u0448\u0438\u0445   \u043f\u043e\u043b\u043e\u0432\u0438\u0446,    \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0433\u0430\u0435\u043c\u044b\u0445 \u0441\u0443\u043d\u0434\u0443\u043a\u043e\u0432,  \u043d\u0430\u043f\u043e\u043b\u043d\u0438\u0432  \u0441\u043e\u0431\u043e\u044e  \u0432\u0435\u0441\u044c \u0434\u043e\u043c, \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0444\u0440\u0430\u043d\u0446\u0443\u0436\u0435\u043d\u043a\u0430.<\/em><\/p>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u044f\u0442\u044b\u0445 \u043d\u0430 1000 \u0441\u043b\u043e\u0432 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f, \u0438 \u044d\u0442\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e &#8212; \u0432 \u0434\u043b\u0438\u043d\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0438\u0445, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0438 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0430\u043d\u0430\u043b\u0438\u0437 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e \u043b\u044e\u0431\u043e\u043c\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c, \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u0443 \u0440\u0430\u0437\u043d\u044b\u0445 \u0430\u0432\u0442\u043e\u0440\u043e\u0432 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u043a \u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u044f &#171;:&#187;:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0434\u0435\u044f, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043f\u043e\u043d\u044f\u0442\u043d\u0430. &#171;\u041e\u0442\u043f\u0435\u0447\u0430\u0442\u043e\u043a&#187; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0430\u0432\u0442\u043e\u0440\u043e\u0432, \u0438 \u043a\u0430\u043a <a href=\"https:\/\/towardsdatascience.com\/using-nlp-to-identify-redditors-who-control-multiple-accounts-837483c8b782\" rel=\"noopener noreferrer nofollow\">\u0431\u044b\u043b\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e<\/a>, \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u0436\u0435 \u0434\u043b\u044f \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u043e\u043d\u043e\u0432 \u043d\u0430 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u043c \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u043c \u0441\u0430\u0439\u0442\u0435. \u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e \u0434\u043b\u044f \u0440\u0443\u0441\u0441\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430, \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e.<\/p>\n<p>\u041c\u044b \u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u043f\u0440\u043e\u0449\u0435. \u041f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0432 \u0421\u0421\u0421\u0420 \u0434\u0435\u0442\u0441\u043a\u0430\u044f \u043a\u043d\u0438\u0433\u0430 &#171;\u0423\u043b\u0438\u0446\u0430 \u043c\u043b\u0430\u0434\u0448\u0435\u0433\u043e \u0441\u044b\u043d\u0430&#187; \u0438\u043c\u0435\u0435\u0442 \u0434\u0432\u0443\u0445 \u0430\u0432\u0442\u043e\u0440\u043e\u0432, \u041b\u0435\u0432 \u041a\u0430\u0441\u0441\u0438\u043b\u044c \u0438 \u041c\u0430\u043a\u0441 \u041f\u043e\u043b\u044f\u043d\u043e\u0432\u0441\u043a\u0438\u0439. \u041d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u043f\u043e Lexical Diversity. \u041c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0447\u0442\u043e \u043d\u0430\u0447\u0430\u043b\u043e \u043a\u043d\u0438\u0433\u0438 \u043f\u0438\u0441\u0430\u043b \u043e\u0434\u0438\u043d \u0430\u0432\u0442\u043e\u0440, \u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b \u0434\u0440\u0443\u0433\u043e\u0439:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439, \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u0433\u0440\u0430\u0444\u0438\u043a \u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u044f \u0434\u043b\u044f 10 \u043a\u043d\u0438\u0433 \u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u0434\u0430\u043c\u0441\u043a\u043e\u0439 \u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c\u043d\u0438\u0446\u044b, \u0447\u044c\u0438 \u043a\u043d\u0438\u0433\u0438 \u043e\u0434\u043d\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0434\u0430\u0432\u0430\u043b\u0438\u0441\u044c \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435. \u0415\u0449\u0451 \u0442\u043e\u0433\u0434\u0430 \u044f \u0443\u0434\u0438\u0432\u043b\u044f\u043b\u0441\u044f, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c <em>\u0441\u0442\u043e\u043b\u044c\u043a\u043e<\/em> \u043a\u043d\u0438\u0433 \u0432 \u0442\u0430\u043a\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435. \u041e\u0442\u0432\u0435\u0442 \u043b\u0438\u0447\u043d\u043e \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u0441\u0442\u0430\u043b \u043e\u0447\u0435\u0432\u0438\u0434\u0435\u043d, \u043d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e \u0432\u0438\u0434\u043d\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u044f &#8212; \u0441\u0442\u0438\u043b\u044c \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u043e\u0434\u043d\u043e\u0439 \u043a\u043d\u0438\u0433\u0438 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u043c\u043e\u0436\u0435\u0442 \u044d\u0442\u043e \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435, \u0442\u0435\u043e\u0440\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0442\u0430\u043a\u043e\u0435, \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442&#8230;<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u044b\u0435, \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0448\u043a\u043e\u043b\u044c\u043d\u044b\u0435, \u0444\u043e\u0440\u043c\u0443\u043b\u044b, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b.<\/p>\n<p>\u0414\u043b\u044f \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0445 \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f Python 3.7 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u043e\u0434 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u043e\u043c.<\/p>\n<details class=\"spoiler\">\n<summary>text_process.py<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import nltk, codecs import numpy as np import pandas as pd import matplotlib.pyplot as plt from typing import Optional, List import string import glob import sys, os   def get_articles_from_blob(folder: str):     data = []     for path in glob.glob(folder + os.sep + \"*\"):         print(path)         data += get_articles_from_folder(path)     return data  def get_articles_from_folder(folder: str):     data = []     for path in glob.glob(folder + os.sep + \"*.txt\"):         data += get_data_from_file(path)     return [(folder.split(os.sep)[-1], data)]  def get_data_from_file(file_name: str):     print(\"Get data for %s\" % file_name)     try:         doc = codecs.open(file_name, 'r', 'cp1251').read()     except:         doc = codecs.open(file_name, 'r', 'utf-8').read()     chunk_size = 25000     data = []     for part in [doc[i:i+chunk_size] for i in range(0, len(doc) - (len(doc) % chunk_size), chunk_size)]:         data.append(get_data_from_str(part[part.find(' '):part.rfind(' ')]))     return data  def get_data_from_str(doc: str):     tokens = nltk.word_tokenize(doc)     remove_punctuation = str.maketrans('', '', string.punctuation)     tokens_ = [x for x in [t.translate(remove_punctuation).lower() for t in tokens] if len(x) &gt; 0]     text = nltk.Text(tokens_)     lexical_divercity = (len(set(text)) \/ len(text)) * 100      words = set(tokens_)     word_chars = [len(word) for word in words]     mean_word_len = sum(word_chars) \/ float(len(word_chars))      sentences = nltk.sent_tokenize(doc)     sentence_word_length = [len(sent.split()) for sent in sentences]     mean_sentence_len = np.mean(sentence_word_length)      fdist = nltk.probability.FreqDist(nltk.Text(tokens))     commas_per_thousand = (fdist[\",\"] * 1000) \/ fdist.N()     return (lexical_divercity, mean_word_len, mean_sentence_len, commas_per_thousand)   def plot_data(data):     plt.rcParams[\"figure.figsize\"] = (12, 5)     fig, ax = plt.subplots()      plt.title('Lexical diversity')     for author, author_data in data:         plt.plot(list(map(lambda val: val[0], author_data)), label=author)     plt.ylim([40, 70])      # plt.title('Mean Word Length')     # for author, author_data in data:     #     plt.plot(list(map(lambda val: val[1], author_data)), label=author)     # plt.ylim([4, 8])      # plt.title('Mean Sentence Length')     # for author, author_data in data:     #     plt.plot(list(map(lambda val: val[2], author_data)), label=author)     # plt.ylim([0, 30])      # plt.title(\"Commas per thousand\")     # for author, author_data in data:     #     plt.plot(list(map(lambda val: val[3], author_data)), label=author)      plt.legend(loc='upper right')     plt.tight_layout()     plt.show()   if __name__ == \"__main__\":     # Download punkt tokenizer     try:         nltk.data.find('tokenizers\/punkt')     except LookupError:         nltk.download('punkt')      # Process text files     # data = get_articles_from_blob(\"Folder\")  # Folder\/AuthorXX\/Text.txt     data = get_articles_from_folder(\"folder_here\")  # Folder with <\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-316218","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/316218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=316218"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/316218\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=316218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=316218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=316218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}