-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01e689e
commit 14684ad
Showing
10 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
Analysis functions | ||
""" | ||
from django.conf import settings | ||
|
||
|
||
def analyze_one_item(item, dictionary=None, language="russian", printer=print): | ||
""" | ||
Analyze one item for tokenize | ||
""" | ||
printer(f'Get tokens for {item}...') | ||
tokens = settings.TOKENIZE(item, language=language, dictionary=dictionary) | ||
printer('Done:') | ||
printer(tokens) | ||
printer('End') | ||
return tokens |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
Command to get tokens from one text | ||
""" | ||
from django.core.management.base import BaseCommand | ||
from analysis.functions import analyze_one_item | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
>> python manage.py tokenize_one "some text" "other text" | ||
Get tokens for some text... | ||
Done: | ||
{'text', 'some'} | ||
End | ||
Get tokens for other text... | ||
Done: | ||
{'other', 'text'} | ||
End | ||
""" | ||
help = "Get tokens from one text" | ||
|
||
def add_arguments(self, parser): | ||
""" | ||
Add arguments to console command | ||
""" | ||
parser.add_argument("text", nargs="+", type=str) | ||
|
||
def handle(self, *args, **options): | ||
""" | ||
Run command handler | ||
""" | ||
for text_item in options["text"]: | ||
analyze_one_item(text_item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
""" | ||
Analysis models | ||
Analisys models | ||
""" | ||
# from django.db import models | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
Tests for Analysis functions | ||
""" | ||
from django.test import SimpleTestCase | ||
|
||
from analysis.functions import analyze_one_item | ||
|
||
|
||
class TestFunctions(SimpleTestCase): | ||
""" | ||
Class for test all functions | ||
""" | ||
def setUp(self): | ||
self.printer = print | ||
|
||
def mock_printer(*args, **kwargs): # pylint: disable=unused-argument | ||
""" | ||
This is mock printer. This printer do nothing | ||
""" | ||
|
||
self.mock_printer = mock_printer | ||
|
||
class TestingPrinter: | ||
""" | ||
Save prints to variable. To check the results | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
Init printer | ||
""" | ||
self.results = [] | ||
|
||
def __call__(self, text, *args, **kwargs): | ||
self.results.append(str(text)) | ||
|
||
self.testing_printer = TestingPrinter() | ||
|
||
def test_analyze_one_item(self): | ||
""" | ||
Test for analyze one item | ||
""" | ||
text = 'one two' | ||
tokens = analyze_one_item('one two', printer=self.testing_printer) | ||
expected_tokens = {'one', 'two'} | ||
self.assertEqual(tokens, expected_tokens) | ||
excepted_prints = [ | ||
f'Get tokens for {text}...', | ||
'Done:', | ||
f'{expected_tokens}', | ||
'End', | ||
] | ||
self.assertEqual(self.testing_printer.results, excepted_prints) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters