-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_pipelines.py
59 lines (50 loc) · 2.44 KB
/
test_pipelines.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
from tempfile import TemporaryDirectory
from unittest import TestCase, main
from unittest.mock import Mock
import pandas as pd
import aggregation.pipelines
from clustering.linkage_name import LinkageName
from clustering.metric_name import MetricName
from data.corpus_handler import CorpusHandler
from data.corpus_name import CorpusName
from grimm_bert import DEFAULT_MODEL_CACHE_PATH
class TestPipelines(TestCase):
def setUp(self):
self.config = {'corpus_name': CorpusName.TOY,
'get_sentences.return_value': pd.DataFrame({
'sentence': [['hello', 'world', '!']]}),
'get_sentences_as_list.return_value':
[['hello', 'world', '!']],
'get_tagged_tokens.return_value': pd.DataFrame({
'token': ['hello', 'world', '!'],
'sense': ['a', 'b', 'c'],
'tagged_sense': [True, True, False]})
}
current_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(os.path.join(current_path, '..'))
def test_create_dictionary_with_known_sense_counts(self):
""" Should execute the pipeline without errors. """
with TemporaryDirectory() as res_path:
aggregation.pipelines.create_dictionary_with_known_sense_counts(
Mock(CorpusHandler, **self.config), DEFAULT_MODEL_CACHE_PATH,
res_path, MetricName.EUCLIDEAN, LinkageName.SINGLE, 'exp_name',
{'a': 1})
def test_create_dictionary_with_max_distance(self):
""" Should execute the pipeline without errors. """
with TemporaryDirectory() as res_path:
aggregation.pipelines.create_dictionary_with_max_distance(
Mock(CorpusHandler, **self.config),
DEFAULT_MODEL_CACHE_PATH, res_path,
MetricName.EUCLIDEAN, LinkageName.SINGLE, 0.2, 'exp_name',
{'a': 1})
def test_create_dictionary_with_min_silhouette(self):
""" Should execute the pipeline without errors. """
with TemporaryDirectory() as res_path:
aggregation.pipelines.create_dictionary_with_min_silhouette(
Mock(CorpusHandler, **self.config),
DEFAULT_MODEL_CACHE_PATH, res_path,
MetricName.EUCLIDEAN, LinkageName.SINGLE, 0.1, 'exp_name',
{'a': 1})
if __name__ == '__main__':
main()