Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests pass #11

Open
wants to merge 1 commit into
base: languagetools
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ bumpversion==0.5.3
wheel==0.23.0
watchdog==0.8.3
flake8==2.4.1
tox==2.1.1
codecov==2.0.9
coverage==4.0
tox==4.10.0
codecov==2.1.13
coverage==7.3.0
Sphinx==1.3.1
cryptography==1.0.1
cryptography==3.3
PyYAML==3.11
pytest==2.8.3
pytest-cov==2.5.0
pytest==7.4.0
pytest-cov==4.1.0
regex==2021.11.10
8 changes: 4 additions & 4 deletions tests/test_tokenize_uk.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_word_tokenization(self):
"Комп'ютер"]

def test_sent_tokenization(self):
assert len(tokenize_sents("""Результати цих досліджень опубліковано в таких колективних працях, як «Статистичні параметри
стилів», «Морфемна структура слова», «Структурна граматика української мови Проспект», «Частотний словник сучасної української художньої прози», «Закономірності структурної організації науково-реферативного тексту», «Морфологічний аналіз наукового тексту на ЕОМ», «Синтаксичний аналіз наукового тексту на ЕОМ», «Використання ЕОМ у лінгвістичних дослідженнях» та ін. за участю В.І.Перебийніс,
М.М.Пещак, М.П.Муравицької, Т.О.Грязнухіної, Н.П.Дарчук, Н.Ф.Клименко, Л.І.Комарової, В.І.Критської,
Т.К.Пуздирєвої, Л.В.Орлової, Л.А.Алексієнко, Т.І.Недозим.""")) == 1
assert len(tokenize_sents("""Результати цих досліджень опубліковано в таких колективних працях, як «Статистичні параметри
стилів», «Морфемна структура слова», «Структурна граматика української мови Проспект», «Частотний словник сучасної української художньої прози», «Закономірності структурної організації науково-реферативного тексту», «Морфологічний аналіз наукового тексту на ЕОМ», «Синтаксичний аналіз наукового тексту на ЕОМ», «Використання ЕОМ у лінгвістичних дослідженнях» та ін. за участю В.І.Перебийніс,
М.М.Пещак, М.П.Муравицької, Т.О.Грязнухіної, Н.П.Дарчук, Н.Ф.Клименко, Л.І.Комарової, В.І.Критської,
Т.К.Пуздирєвої, Л.В.Орлової, Л.А.Алексієнко, Т.І.Недозим.""")) == 1
76 changes: 76 additions & 0 deletions tokenize_uk/tokenize_uk.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,79 @@ def split_with_delimiters(self, text: str, delim_pattern: re.Pattern) -> list[st
parts.append(non_delim)

return parts

def tokenize_text(string: str) -> list[list[list[str]]]:
"""
Tokenize input text to paragraphs, sentences and words.

Tokenization to paragraphs is done using simple Newline algorithm
For sentences and words tokenizers above are used

:param string: Text to tokenize
:type string: str or unicode
:return: text, tokenized into paragraphs, sentences and words
:rtype: list of list of list of words
"""
tokenizer = UkrainianWordTokenizer()
tokens = tokenizer.tokenize(text=string)
paragraphs = []
sentences : list[list[str]] = []
current_sentence: list[str] = []
for w in tokens:
if w == " ":
continue
if w == ".":
current_sentence.append(w)
sentences.append(current_sentence)
current_sentence = []
elif w == "\n":
paragraphs.append(sentences)
sentences = []
else:
current_sentence.append(w)

if len(current_sentence) > 0:
sentences.append(current_sentence)
if len(sentences) > 0:
paragraphs.append(sentences)
return paragraphs

def tokenize_words(string):
"""
Tokenize input text to words.

:param string: Text to tokenize
:type string: str or unicode
:return: words
:rtype: list of strings
"""
tokenizer = UkrainianWordTokenizer()
tokens = tokenizer.tokenize(text=string)
words = [w for w in tokens if w != ' ']
return words

def tokenize_sents(string):
"""
Tokenize input text to sentences.

:param string: Text to tokenize
:type string: str or unicode
:return: sentences
:rtype: list of strings
"""
tokenizer = UkrainianWordTokenizer()
tokens = tokenizer.tokenize(text=string)
sentences = []
current_sentence = ""
for w in tokens:
if w != ".":
current_sentence += w
else:
sentences.append(current_sentence)
current_sentence = ""
if current_sentence != "":
sentences.append(current_sentence)
return sentences

__all__ = [
"tokenize_words", "tokenize_text", "tokenize_sents", "UkrainianWordTokenizer"]
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py26, py27, py33, py34, py35
envlist = py36, py10, py11

[testenv]
passenv = CI TRAVIS TRAVIS_*
Expand Down