Skip to main content

библиотека по обработке текстов

Project description

SONYA_PROGECT library

Author S.A.Galinovskaya

This code is intended for text processing, namely, determining the number of certain particles, plotting the length of sentences.

def __init__(self, name, particle, quantity):
    self.quantity = quantity
    self.particle = particle
    self.name = name
    try:
        self.doc = codecs.open(self.name, 'r', 'utf-8').read()
    except:
        self.doc = codecs.open(self.name, 'r', 'cp1251').read()

def sentences_word_length(self):
    sentences = nltk.sent_tokenize(self.doc)
    sentences_word_length = [len(sent.split()) for sent in sentences]
    return sentences_word_length

@staticmethod
def text_sentences_length(sentences_word_length):
    average_sentences_word_length = (sum(sentences_word_length) / len(sentences_word_length))
    return average_sentences_word_length

def tokenize(self):
    word = nltk.word_tokenize(self.doc)
    remove_punctuation = str.maketrans('', '', string.punctuation)
    tokens_ = [x for x in [t.translate(remove_punctuation).lower() for t in word] if len(x) > 0]
    return tokens_

@staticmethod
def words_length(tokens_):
    words = set(tokens_)
    word_chars = [len(word) for word in words]
    return word_chars

@staticmethod
def text_lexical(tokens_):
    lexical_diversity = (len(set(tokens_)) / len(tokens_)) * 100
    return lexical_diversity

@staticmethod
def word_mean_length(word_chars):
    mean_word_len = sum(word_chars) / float(len(word_chars))
    return mean_word_len

def commas_in_text(self):
    tokens = nltk.word_tokenize(self.doc)
    dist = nltk.probability.FreqDist(nltk.Text(tokens))
    commas_per_quantity = (dist[self.particle] * self.quantity) / dist.N()
    return commas_per_quantity

@staticmethod
def visual_thinks(sentences_word_length):
    x_list = list(range(0, len(sentences_word_length)))
    y1_list = list(sentences_word_length)
    plt.plot(x_list, y1_list)
    plt.ylabel("Длина предложений", fontsize=14, fontweight="bold")
    plt.show()

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sonya_library-1.0.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sonya_library-1.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file sonya_library-1.0.tar.gz.

File metadata

  • Download URL: sonya_library-1.0.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

File hashes

Hashes for sonya_library-1.0.tar.gz
Algorithm Hash digest
SHA256 197e583ded4c4530a83fc2a9deb7b9703096169d319ab41eeaa10bdcea11dcc2
MD5 5f669b960577614147f1750b65a41049
BLAKE2b-256 60e532386883a32a045bc9548cbf48c0cb52982035a17801d9ce3942b4d8e329

See more details on using hashes here.

File details

Details for the file sonya_library-1.0-py3-none-any.whl.

File metadata

  • Download URL: sonya_library-1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

File hashes

Hashes for sonya_library-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b84d41c650862ddd9fce70ce99b4ad69a65957994594892b34841be364ed7aa
MD5 269a7aeb1d2b716550c935292ee80661
BLAKE2b-256 0a431678663f6441bbffb6fb78e731ad581dbd640406014503aaabab19c92a3e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page