This repository was archived by the owner on May 25, 2022. It is now read-only.
forked from gpassero/cogroo4py
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
86 lines (68 loc) · 2.6 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
# -*- coding: utf-8 -*-
import unittest
from cogroo_interface import Cogroo, Document
class LemmaTest(unittest.TestCase):
def setUp(self):
self.cogroo = Cogroo.instance()
def test_singleton(self):
excpt_thrown = False
try:
Cogroo()
except TypeError, e:
excpt_thrown = True
self.assertEquals(Cogroo.MSG_CALL_INSTANCE, '%s' % e)
self.assertTrue(excpt_thrown)
def test_lemma(self):
lemma = self.cogroo.lemmatize('Estas laranjas estão deliciosas.')
self.assertTrue(isinstance(lemma, unicode))
self.assertEquals(
lemma,
'este laranja estar delicioso .'
)
self.assertEquals(self.cogroo.lemmatize(''), '')
def test_morpho_analysis(self):
doc = self.cogroo.analyze(
'Estas laranjas estão deliciosas. Esta frase, e a outra.'
)
self.assertIsNotNone(doc)
self.assertTrue(isinstance(doc, Document))
self.assertNotEqual('%s' % doc.sentences[0].tokens, '')
self.assertNotEqual('%s' % doc.sentences[0].chunks, '')
self.assertNotEqual('%s' % doc.sentences, '')
self.assertNotEqual('%s' % doc, '')
def test_grammar_checker(self):
doc = self.cogroo.grammar_check(
'Elas são bonita.\nEles é feio.'
)
self.assertIsNotNone(doc)
self.assertNotEquals(doc.mistakes, [])
self.assertTrue(isinstance(doc, Document))
self.assertNotEqual('%s' % doc.mistakes, '')
def test_post_tag(self):
pos_tag = self.cogroo.pos_tag(
'Bem-aventurados os pacificadores, '
'porque eles serão chamados filhos de Deus.'
)
self.assertEquals(
pos_tag,
u'Bem#prop -#- aventurados#v-pcp os#art pacificadores#n ,#, '
u'porque#conj-s eles#pron-pers serão#v-fin chamados#v-pcp filhos#n '
u'de#prp Deus#prop .#.'
)
def test_chunk_tag(self):
chunk_tag_normal = self.cogroo.chunk_tag(
'Bem-aventurados os misericordiosos, '
'porque eles alcançarão misericórdia.',
'normal'
)
self.assertTrue(isinstance(chunk_tag_normal, unicode))
self.assertNotEqual(chunk_tag_normal, u'')
chunk_tag_sync = self.cogroo.chunk_tag(
'Bem-aventurados os misericordiosos, '
'porque eles alcançarão misericórdia.',
'sync'
)
self.assertTrue(isinstance(chunk_tag_sync, unicode))
self.assertNotEqual(chunk_tag_sync, u'')
if __name__ == '__main__':
unittest.main()