Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/all.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/childes_fixt.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/classify_fixt.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/conftest.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/gensim_fixt.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/gluesemantics_malt_fixt.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/portuguese_en_fixt.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/probability_fixt.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/setup_fixt.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__init__.py +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_aline.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_bllip.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_brill.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_cfd_mutation.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_cfg2chomsky.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_chunk.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_classify.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_collocations.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_concordance.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_corenlp.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_corpora.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_corpus_views.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_data.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_disagreement.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_distance.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_downloader.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_freqdist.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_hmm.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_json2csv_corpus.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_json_serialization.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_metrics.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_naivebayes.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_nombank.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_pl196x.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_pos_tag.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_ribes.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_rte_classify.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_seekable_unicode_stream_reader.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_senna.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_stem.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_tag.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_tgrep.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_tokenize.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_twitter_auth.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_util.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_wordnet.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/lm/__init__.py +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/lm/test_counter.py +116 -0
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (462 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/all.cpython-310.pyc
ADDED
|
Binary file (1.1 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/childes_fixt.cpython-310.pyc
ADDED
|
Binary file (611 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/classify_fixt.cpython-310.pyc
ADDED
|
Binary file (343 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/conftest.cpython-310.pyc
ADDED
|
Binary file (1.03 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/gensim_fixt.cpython-310.pyc
ADDED
|
Binary file (342 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/gluesemantics_malt_fixt.cpython-310.pyc
ADDED
|
Binary file (527 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/portuguese_en_fixt.cpython-310.pyc
ADDED
|
Binary file (402 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/probability_fixt.cpython-310.pyc
ADDED
|
Binary file (346 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/__pycache__/setup_fixt.cpython-310.pyc
ADDED
|
Binary file (1.24 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__init__.py
ADDED
|
File without changes
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (188 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_aline.cpython-310.pyc
ADDED
|
Binary file (1.13 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_bllip.cpython-310.pyc
ADDED
|
Binary file (1.7 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_brill.cpython-310.pyc
ADDED
|
Binary file (1.32 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_cfd_mutation.cpython-310.pyc
ADDED
|
Binary file (1.45 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_cfg2chomsky.cpython-310.pyc
ADDED
|
Binary file (1.64 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_chunk.cpython-310.pyc
ADDED
|
Binary file (1.95 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_classify.cpython-310.pyc
ADDED
|
Binary file (1.49 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_collocations.cpython-310.pyc
ADDED
|
Binary file (2.62 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_concordance.cpython-310.pyc
ADDED
|
Binary file (5.12 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_corenlp.cpython-310.pyc
ADDED
|
Binary file (11.2 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_corpora.cpython-310.pyc
ADDED
|
Binary file (7.51 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_corpus_views.cpython-310.pyc
ADDED
|
Binary file (1.67 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_data.cpython-310.pyc
ADDED
|
Binary file (774 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_disagreement.cpython-310.pyc
ADDED
|
Binary file (2.55 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_distance.cpython-310.pyc
ADDED
|
Binary file (2.21 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_downloader.cpython-310.pyc
ADDED
|
Binary file (932 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_freqdist.cpython-310.pyc
ADDED
|
Binary file (466 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_hmm.cpython-310.pyc
ADDED
|
Binary file (2.11 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_json2csv_corpus.cpython-310.pyc
ADDED
|
Binary file (5 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_json_serialization.cpython-310.pyc
ADDED
|
Binary file (3.44 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_metrics.cpython-310.pyc
ADDED
|
Binary file (1.72 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_naivebayes.cpython-310.pyc
ADDED
|
Binary file (936 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_nombank.cpython-310.pyc
ADDED
|
Binary file (1.37 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_pl196x.cpython-310.pyc
ADDED
|
Binary file (821 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_pos_tag.cpython-310.pyc
ADDED
|
Binary file (2.37 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_ribes.cpython-310.pyc
ADDED
|
Binary file (2.26 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_rte_classify.cpython-310.pyc
ADDED
|
Binary file (3.18 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_seekable_unicode_stream_reader.cpython-310.pyc
ADDED
|
Binary file (2.05 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_senna.cpython-310.pyc
ADDED
|
Binary file (3.3 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_stem.cpython-310.pyc
ADDED
|
Binary file (5.6 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_tag.cpython-310.pyc
ADDED
|
Binary file (748 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_tgrep.cpython-310.pyc
ADDED
|
Binary file (20.6 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_tokenize.cpython-310.pyc
ADDED
|
Binary file (18.1 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_twitter_auth.cpython-310.pyc
ADDED
|
Binary file (2.38 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_util.cpython-310.pyc
ADDED
|
Binary file (1.5 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/__pycache__/test_wordnet.cpython-310.pyc
ADDED
|
Binary file (7.41 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/lm/__init__.py
ADDED
|
File without changes
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/nltk/test/unit/lm/test_counter.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Natural Language Toolkit: Language Model Unit Tests
|
| 2 |
+
#
|
| 3 |
+
# Copyright (C) 2001-2023 NLTK Project
|
| 4 |
+
# Author: Ilia Kurenkov <ilia.kurenkov@gmail.com>
|
| 5 |
+
# URL: <https://www.nltk.org/>
|
| 6 |
+
# For license information, see LICENSE.TXT
|
| 7 |
+
|
| 8 |
+
import unittest
|
| 9 |
+
|
| 10 |
+
import pytest
|
| 11 |
+
|
| 12 |
+
from nltk import FreqDist
|
| 13 |
+
from nltk.lm import NgramCounter
|
| 14 |
+
from nltk.util import everygrams
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class TestNgramCounter:
|
| 18 |
+
"""Tests for NgramCounter that only involve lookup, no modification."""
|
| 19 |
+
|
| 20 |
+
@classmethod
|
| 21 |
+
def setup_class(self):
|
| 22 |
+
text = [list("abcd"), list("egdbe")]
|
| 23 |
+
self.trigram_counter = NgramCounter(
|
| 24 |
+
everygrams(sent, max_len=3) for sent in text
|
| 25 |
+
)
|
| 26 |
+
self.bigram_counter = NgramCounter(everygrams(sent, max_len=2) for sent in text)
|
| 27 |
+
self.case = unittest.TestCase()
|
| 28 |
+
|
| 29 |
+
def test_N(self):
|
| 30 |
+
assert self.bigram_counter.N() == 16
|
| 31 |
+
assert self.trigram_counter.N() == 21
|
| 32 |
+
|
| 33 |
+
def test_counter_len_changes_with_lookup(self):
|
| 34 |
+
assert len(self.bigram_counter) == 2
|
| 35 |
+
self.bigram_counter[50]
|
| 36 |
+
assert len(self.bigram_counter) == 3
|
| 37 |
+
|
| 38 |
+
def test_ngram_order_access_unigrams(self):
|
| 39 |
+
assert self.bigram_counter[1] == self.bigram_counter.unigrams
|
| 40 |
+
|
| 41 |
+
def test_ngram_conditional_freqdist(self):
|
| 42 |
+
case = unittest.TestCase()
|
| 43 |
+
expected_trigram_contexts = [
|
| 44 |
+
("a", "b"),
|
| 45 |
+
("b", "c"),
|
| 46 |
+
("e", "g"),
|
| 47 |
+
("g", "d"),
|
| 48 |
+
("d", "b"),
|
| 49 |
+
]
|
| 50 |
+
expected_bigram_contexts = [("a",), ("b",), ("d",), ("e",), ("c",), ("g",)]
|
| 51 |
+
|
| 52 |
+
bigrams = self.trigram_counter[2]
|
| 53 |
+
trigrams = self.trigram_counter[3]
|
| 54 |
+
|
| 55 |
+
self.case.assertCountEqual(expected_bigram_contexts, bigrams.conditions())
|
| 56 |
+
self.case.assertCountEqual(expected_trigram_contexts, trigrams.conditions())
|
| 57 |
+
|
| 58 |
+
def test_bigram_counts_seen_ngrams(self):
|
| 59 |
+
assert self.bigram_counter[["a"]]["b"] == 1
|
| 60 |
+
assert self.bigram_counter[["b"]]["c"] == 1
|
| 61 |
+
|
| 62 |
+
def test_bigram_counts_unseen_ngrams(self):
|
| 63 |
+
assert self.bigram_counter[["b"]]["z"] == 0
|
| 64 |
+
|
| 65 |
+
def test_unigram_counts_seen_words(self):
|
| 66 |
+
assert self.bigram_counter["b"] == 2
|
| 67 |
+
|
| 68 |
+
def test_unigram_counts_completely_unseen_words(self):
|
| 69 |
+
assert self.bigram_counter["z"] == 0
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class TestNgramCounterTraining:
|
| 73 |
+
@classmethod
|
| 74 |
+
def setup_class(self):
|
| 75 |
+
self.counter = NgramCounter()
|
| 76 |
+
self.case = unittest.TestCase()
|
| 77 |
+
|
| 78 |
+
@pytest.mark.parametrize("case", ["", [], None])
|
| 79 |
+
def test_empty_inputs(self, case):
|
| 80 |
+
test = NgramCounter(case)
|
| 81 |
+
assert 2 not in test
|
| 82 |
+
assert test[1] == FreqDist()
|
| 83 |
+
|
| 84 |
+
def test_train_on_unigrams(self):
|
| 85 |
+
words = list("abcd")
|
| 86 |
+
counter = NgramCounter([[(w,) for w in words]])
|
| 87 |
+
|
| 88 |
+
assert not counter[3]
|
| 89 |
+
assert not counter[2]
|
| 90 |
+
self.case.assertCountEqual(words, counter[1].keys())
|
| 91 |
+
|
| 92 |
+
def test_train_on_illegal_sentences(self):
|
| 93 |
+
str_sent = ["Check", "this", "out", "!"]
|
| 94 |
+
list_sent = [["Check", "this"], ["this", "out"], ["out", "!"]]
|
| 95 |
+
|
| 96 |
+
with pytest.raises(TypeError):
|
| 97 |
+
NgramCounter([str_sent])
|
| 98 |
+
|
| 99 |
+
with pytest.raises(TypeError):
|
| 100 |
+
NgramCounter([list_sent])
|
| 101 |
+
|
| 102 |
+
def test_train_on_bigrams(self):
|
| 103 |
+
bigram_sent = [("a", "b"), ("c", "d")]
|
| 104 |
+
counter = NgramCounter([bigram_sent])
|
| 105 |
+
assert not bool(counter[3])
|
| 106 |
+
|
| 107 |
+
def test_train_on_mix(self):
|
| 108 |
+
mixed_sent = [("a", "b"), ("c", "d"), ("e", "f", "g"), ("h",)]
|
| 109 |
+
counter = NgramCounter([mixed_sent])
|
| 110 |
+
unigrams = ["h"]
|
| 111 |
+
bigram_contexts = [("a",), ("c",)]
|
| 112 |
+
trigram_contexts = [("e", "f")]
|
| 113 |
+
|
| 114 |
+
self.case.assertCountEqual(unigrams, counter[1].keys())
|
| 115 |
+
self.case.assertCountEqual(bigram_contexts, counter[2].keys())
|
| 116 |
+
self.case.assertCountEqual(trigram_contexts, counter[3].keys())
|