This repository has been archived by the owner on Jan 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
125 lines (106 loc) · 4.39 KB
/
tests.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# encoding=UTF-8
# Copyright © 2007-2017 Jakub Wilk <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the “Software”), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import sys
if sys.version_info >= (2, 7):
import unittest
else:
import unittest2 as unittest
import morfeusz
if str is bytes:
def u(s):
return s.decode('UTF-8')
else:
def u(s):
return s
sgjp = 'SGJP' in morfeusz.about()
class test_expand_tags(unittest.TestCase):
def test1(self):
tags = 'adj:sg:nom:m1.m2.m3:pos|adj:sg:acc:m3:pos'
xtags = morfeusz.expand_tags(tags)
self.assertEqual(list(xtags), [
'adj:sg:nom:m1:pos',
'adj:sg:nom:m2:pos',
'adj:sg:nom:m3:pos',
'adj:sg:acc:m3:pos',
])
def test2(self):
tags = 'adj:sg:nom:m1.m2.m3:pos|adj:sg:acc:m3:pos'
xtags = morfeusz.expand_tags(tags, expand_dot=False)
self.assertEqual(list(xtags), [
'adj:sg:nom:m1.m2.m3:pos',
'adj:sg:acc:m3:pos'
])
def test3(self):
tags = 'ppron3:sg:acc:f:ter:_:npraep'
xtags = morfeusz.expand_tags(tags)
self.assertEqual(list(xtags), [
'ppron3:sg:acc:f:ter:akc:npraep',
'ppron3:sg:acc:f:ter:nakc:npraep'
])
def test4(self):
tags = 'ppron3:sg:acc:f:ter:_:npraep'
xtags = morfeusz.expand_tags(tags, expand_dot=False)
self.assertEqual(list(xtags), [
'ppron3:sg:acc:f:ter:akc.nakc:npraep'
])
def test5(self):
tags = 'ppron3:sg:acc:f:ter:_:npraep'
xtags = morfeusz.expand_tags(tags, expand_underscore=False)
self.assertEqual(list(xtags), [
'ppron3:sg:acc:f:ter:_:npraep'
])
class test_analyse(unittest.TestCase):
def test1(self):
text = 'Mama ma.'
interps = morfeusz.analyse(text)
if sgjp:
self.assertEqual(interps.pop(),
[(u('Mama'), u('mama'), 'subst:sg:nom:f'), (u('ma'), u('mój'), 'adj:sg:voc:f:pos'), (u('.'), u('.'), 'interp')]
)
self.assertEqual(interps, [
[(u('Mama'), u('mama'), 'subst:sg:nom:f'), (u('ma'), u('mieć'), 'fin:sg:ter:imperf'), (u('.'), u('.'), 'interp')],
[(u('Mama'), u('mama'), 'subst:sg:nom:f'), (u('ma'), u('mój'), 'adj:sg:nom:f:pos'), (u('.'), u('.'), 'interp')]
])
def test2(self):
text = u('Miałem miał.')
interps = morfeusz.analyse(text, dag=True)
self.assertEqual(interps, [
(0, 1, (u('Miał'), u('mieć'), u('praet:sg:m1:imperf'))),
(0, 1, (u('Miał'), u('mieć'), u('praet:sg:m2:imperf'))),
(0, 1, (u('Miał'), u('mieć'), u('praet:sg:m3:imperf'))),
(1, 2, (u('em'), u('być'), u('aglt:sg:pri:imperf:wok'))),
(0, 2, (u('Miałem'), u('miał'), u('subst:sg:inst:m3'))),
(2, 3, (u('miał'), u('miał'), u('subst:sg:nom:m3'))),
(2, 3, (u('miał'), u('miał'), u('subst:sg:acc:m3'))),
(2, 3, (u('miał'), u('mieć'), u('praet:sg:m1:imperf'))),
(2, 3, (u('miał'), u('mieć'), u('praet:sg:m2:imperf'))),
(2, 3, (u('miał'), u('mieć'), u('praet:sg:m3:imperf'))),
(3, 4, (u('.'), u('.'), u('interp'))),
])
class test_about(unittest.TestCase):
def test_type(self):
self.assertEqual(
type(morfeusz.about()),
type(u(''))
)
if __name__ == '__main__':
unittest.main()
# vim:ts=4 sts=4 sw=4 et