-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapitests.py
201 lines (178 loc) · 6.24 KB
/
apitests.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2009-2011 CREA Lab, CNRS/Ecole Polytechnique UMR 7656 (Fr)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
__author__ = "[email protected]"
# core modules
import unittest
import sys
from tinasoft import PytextminerApi
class PytextminerApiTest(unittest.TestCase):
"""
Base test class
"""
def setUp(self):
self.tinasoft = tinasoftSingleton
self.datasetId = argument3
self.period = argument5
self.whitelist = argument4
self.argument1 = argument1
self.argument2 = argument2
class ExtractFile(PytextminerApiTest):
def runTest(self):
"""ExtractFile : extract a source file's word vectors"""
print self.tinasoft.extract_file(
self.argument1,
self.datasetId,
outpath=self.whitelist,
format=self.argument2,
minoccs=1,
)
self.failIfEqual(self.whitelist, PytextminerApi.STATUS_ERROR)
class IndexFile(PytextminerApiTest):
def runTest(self):
"""
IndexFile :
index a whitelist against a source file
and its network in the db
"""
self.failIfEqual(self.tinasoft.index_file(
self.argument1,
self.datasetId,
whitelistpath=self.whitelist,
format=self.argument2
), PytextminerApi.STATUS_ERROR
)
class GenerateGraph(PytextminerApiTest):
def runTest(self):
"""ExportGraph : processes a graph, and exports a gexf graph,"""
print self.tinasoft.generate_graph(
self.datasetId,
self.period,
#whitelistpath = self.whitelist,
outpath = 'test_graph',
ngramgraphconfig={
# 'edgethreshold': [1.0,'inf'],
# 'nodethreshold': [1,'inf'],
# 'alpha': 0.1,
'proximity': self.argument1
},
documentgraphconfig={
# 'edgethreshold': [1.0,'inf'],
# 'nodethreshold': [1,'inf'],
'proximity': self.argument2
},
exportedges=True
)
class IndexArchive(PytextminerApiTest):
def runTest(self):
"""
IndexArchive : process cooccurences on an archive data type (see tinasoft/data/*archive.py)
"""
def getAllSubdirectories(source_dir):
from glob import glob
from os.path import join
allP=glob(join('source_files',source_dir,'*'))
filtered = [p.split("/")[-1] for p in allP]
return filtered
if self.period == "all":
self.period = getAllSubdirectories(self.argument1)
else:
self.period = [self.period]
print self.period
print self.tinasoft.index_archive(
self.argument1,
self.datasetId,
self.period,
self.whitelist,
self.argument2,
outpath=True,
minCooc=10
)
class ExportCoocMatrix(PytextminerApiTest):
def runTest(self):
"""testF_ExportCoocMatrix"""
datasetObj= self.tinasoft.storage.loadCorpora(self.datasetId)
if datasetObj is not None:
for periodid in datasetObj['edges']['Corpus'].keys():
print self.tinasoft.export_cooc(self.datasetId, periodid)
def usage():
print " apitests.py USAGE :\n"
print " python apitests.py ExtractFile configuration_file_path source_filename source_file_format dataset_name whitelist_out_path\n"
print " python apitests.py IndexFile configuration_file_path source_filename source_file_format dataset_name whitelist_path\n"
print " python apitests.py GenerateGraph configuration_file_path ngram_proximity_name document_proximity_name dataset_name period\n"
print " python apitests.py IndexArchive configuration_file_path source_filename source_file_format dataset_name whitelist_path period\n"
print " python apitests.py ExportCoocMatrix configuration_file_path\n"
if __name__ == '__main__':
print sys.argv
argument1 = None
argument2 = None
argument3 = None
argument4 = None
argument5 = None
try:
testclass = sys.argv[1]
confFile = sys.argv[2]
except Exception, e:
print e
usage()
exit()
if testclass in ['ExtractFile','IndexFile']:
try:
argument1 = sys.argv[3]
argument2 = sys.argv[4]
argument3 = sys.argv[5]
argument4 = sys.argv[6]
del sys.argv[2:]
except Exception, e:
print e
usage()
exit()
if testclass in ['GenerateGraph']:
try:
argument1 = sys.argv[3]
argument2 = sys.argv[4]
argument3 = sys.argv[5]
if len(sys.argv) == 7:
argument5 = sys.argv[6]
else:
argument5 = None
del sys.argv[2:]
except Exception, e:
print e
usage()
exit()
if testclass in ['IndexArchive']:
try:
argument1 = sys.argv[3]
argument2 = sys.argv[4]
argument3 = sys.argv[5]
argument4 = sys.argv[6]
argument5 = sys.argv[7]
del sys.argv[2:]
except Exception, e:
print e
usage()
exit()
if testclass in ['ExportCoocMatrix']:
try:
argument3 = sys.argv[3]
del sys.argv[2:]
except Exception, e:
print e
usage()
exit()
tinasoftSingleton = PytextminerApi(confFile)
unittest.main()