opener-opinion-detector-base 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +101 -0
  3. data/bin/opinion-detector-base +19 -0
  4. data/core/annotation.cfg.erb +9 -0
  5. data/core/packages/KafNafParser-1.4.tar.gz +0 -0
  6. data/core/packages/VUA_pylib-1.5.tar.gz +0 -0
  7. data/core/python-scripts/LICENSE +339 -0
  8. data/core/python-scripts/README.md +226 -0
  9. data/core/python-scripts/classify_kaf_naf_file.py +499 -0
  10. data/core/python-scripts/cross_validation.py +634 -0
  11. data/core/python-scripts/generate_folds.py +134 -0
  12. data/core/python-scripts/models.cfg +10 -0
  13. data/core/python-scripts/my_templates/README +33 -0
  14. data/core/python-scripts/my_templates/templates_exp.only0.txt +6 -0
  15. data/core/python-scripts/my_templates/templates_exp.pol0.txt +10 -0
  16. data/core/python-scripts/my_templates/templates_exp.red.txt +7 -0
  17. data/core/python-scripts/my_templates/templates_exp.txt +10 -0
  18. data/core/python-scripts/my_templates/templates_holder.only0.txt +11 -0
  19. data/core/python-scripts/my_templates/templates_holder.red.txt +9 -0
  20. data/core/python-scripts/my_templates/templates_holder.txt +10 -0
  21. data/core/python-scripts/my_templates/templates_target.only0.txt +11 -0
  22. data/core/python-scripts/my_templates/templates_target.red.txt +9 -0
  23. data/core/python-scripts/my_templates/templates_target.txt +10 -0
  24. data/core/python-scripts/run_all_experiments.sh +49 -0
  25. data/core/python-scripts/run_basic.py +20 -0
  26. data/core/python-scripts/run_experiment.sh +42 -0
  27. data/core/python-scripts/scripts/__init__.py +1 -0
  28. data/core/python-scripts/scripts/config_manager.py +314 -0
  29. data/core/python-scripts/scripts/crfutils.py +215 -0
  30. data/core/python-scripts/scripts/extract_feats_relations.py +295 -0
  31. data/core/python-scripts/scripts/extract_features.py +376 -0
  32. data/core/python-scripts/scripts/feats_to_crf.exp.py +105 -0
  33. data/core/python-scripts/scripts/lexicons.py +44 -0
  34. data/core/python-scripts/scripts/link_entities_distance.py +77 -0
  35. data/core/python-scripts/scripts/relation_classifier.py +250 -0
  36. data/core/python-scripts/train.py +566 -0
  37. data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/PKG-INFO +10 -0
  38. data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/SOURCES.txt +22 -0
  39. data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/dependency_links.txt +1 -0
  40. data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/installed-files.txt +47 -0
  41. data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/top_level.txt +1 -0
  42. data/core/site-packages/pre_build/KafNafParser/KafNafParserMod.py +390 -0
  43. data/core/site-packages/pre_build/KafNafParser/KafNafParserMod.pyc +0 -0
  44. data/core/site-packages/pre_build/KafNafParser/__init__.py +14 -0
  45. data/core/site-packages/pre_build/KafNafParser/__init__.pyc +0 -0
  46. data/core/site-packages/pre_build/KafNafParser/constituency_data.py +125 -0
  47. data/core/site-packages/pre_build/KafNafParser/constituency_data.pyc +0 -0
  48. data/core/site-packages/pre_build/KafNafParser/coreference_data.py +52 -0
  49. data/core/site-packages/pre_build/KafNafParser/coreference_data.pyc +0 -0
  50. data/core/site-packages/pre_build/KafNafParser/dependency_data.py +78 -0
  51. data/core/site-packages/pre_build/KafNafParser/dependency_data.pyc +0 -0
  52. data/core/site-packages/pre_build/KafNafParser/entity_data.py +59 -0
  53. data/core/site-packages/pre_build/KafNafParser/entity_data.pyc +0 -0
  54. data/core/site-packages/pre_build/KafNafParser/external_references_data.py +41 -0
  55. data/core/site-packages/pre_build/KafNafParser/external_references_data.pyc +0 -0
  56. data/core/site-packages/pre_build/KafNafParser/feature_extractor/__init__.py +2 -0
  57. data/core/site-packages/pre_build/KafNafParser/feature_extractor/__init__.pyc +0 -0
  58. data/core/site-packages/pre_build/KafNafParser/feature_extractor/constituency.py +205 -0
  59. data/core/site-packages/pre_build/KafNafParser/feature_extractor/constituency.pyc +0 -0
  60. data/core/site-packages/pre_build/KafNafParser/feature_extractor/dependency.py +309 -0
  61. data/core/site-packages/pre_build/KafNafParser/feature_extractor/dependency.pyc +0 -0
  62. data/core/site-packages/pre_build/KafNafParser/features_data.py +131 -0
  63. data/core/site-packages/pre_build/KafNafParser/features_data.pyc +0 -0
  64. data/core/site-packages/pre_build/KafNafParser/header_data.py +127 -0
  65. data/core/site-packages/pre_build/KafNafParser/header_data.pyc +0 -0
  66. data/core/site-packages/pre_build/KafNafParser/opinion_data.py +211 -0
  67. data/core/site-packages/pre_build/KafNafParser/opinion_data.pyc +0 -0
  68. data/core/site-packages/pre_build/KafNafParser/references_data.py +23 -0
  69. data/core/site-packages/pre_build/KafNafParser/references_data.pyc +0 -0
  70. data/core/site-packages/pre_build/KafNafParser/span_data.py +63 -0
  71. data/core/site-packages/pre_build/KafNafParser/span_data.pyc +0 -0
  72. data/core/site-packages/pre_build/KafNafParser/term_data.py +111 -0
  73. data/core/site-packages/pre_build/KafNafParser/term_data.pyc +0 -0
  74. data/core/site-packages/pre_build/KafNafParser/term_sentiment_data.py +42 -0
  75. data/core/site-packages/pre_build/KafNafParser/term_sentiment_data.pyc +0 -0
  76. data/core/site-packages/pre_build/KafNafParser/text_data.py +99 -0
  77. data/core/site-packages/pre_build/KafNafParser/text_data.pyc +0 -0
  78. data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/PKG-INFO +10 -0
  79. data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/SOURCES.txt +14 -0
  80. data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/dependency_links.txt +1 -0
  81. data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/installed-files.txt +23 -0
  82. data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/top_level.txt +1 -0
  83. data/core/site-packages/pre_build/VUA_pylib/__init__.py +1 -0
  84. data/core/site-packages/pre_build/VUA_pylib/__init__.pyc +0 -0
  85. data/core/site-packages/pre_build/VUA_pylib/common/__init__.py +1 -0
  86. data/core/site-packages/pre_build/VUA_pylib/common/__init__.pyc +0 -0
  87. data/core/site-packages/pre_build/VUA_pylib/common/common.py +28 -0
  88. data/core/site-packages/pre_build/VUA_pylib/common/common.pyc +0 -0
  89. data/core/site-packages/pre_build/VUA_pylib/corpus_reader/__init__.py +1 -0
  90. data/core/site-packages/pre_build/VUA_pylib/corpus_reader/__init__.pyc +0 -0
  91. data/core/site-packages/pre_build/VUA_pylib/corpus_reader/google_web_nl.py +156 -0
  92. data/core/site-packages/pre_build/VUA_pylib/corpus_reader/google_web_nl.pyc +0 -0
  93. data/core/site-packages/pre_build/VUA_pylib/io_utils/__init__.py +1 -0
  94. data/core/site-packages/pre_build/VUA_pylib/io_utils/__init__.pyc +0 -0
  95. data/core/site-packages/pre_build/VUA_pylib/io_utils/feature_file.py +121 -0
  96. data/core/site-packages/pre_build/VUA_pylib/io_utils/feature_file.pyc +0 -0
  97. data/core/site-packages/pre_build/VUA_pylib/lexicon/__init__.py +1 -0
  98. data/core/site-packages/pre_build/VUA_pylib/lexicon/__init__.pyc +0 -0
  99. data/core/site-packages/pre_build/VUA_pylib/lexicon/lexicon.py +72 -0
  100. data/core/site-packages/pre_build/VUA_pylib/lexicon/lexicon.pyc +0 -0
  101. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/PKG-INFO +10 -0
  102. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/SOURCES.txt +7 -0
  103. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/dependency_links.txt +1 -0
  104. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/installed-files.txt +11 -0
  105. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/top_level.txt +1 -0
  106. data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.py +165 -0
  107. data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.pyc +0 -0
  108. data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.py +439 -0
  109. data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.pyc +0 -0
  110. data/core/site-packages/pre_build/VUKafParserPy/__init__.py +7 -0
  111. data/core/site-packages/pre_build/VUKafParserPy/__init__.pyc +0 -0
  112. data/core/vendor/src/crfsuite/AUTHORS +1 -0
  113. data/core/vendor/src/crfsuite/COPYING +27 -0
  114. data/core/vendor/src/crfsuite/ChangeLog +103 -0
  115. data/core/vendor/src/crfsuite/INSTALL +236 -0
  116. data/core/vendor/src/crfsuite/Makefile.am +19 -0
  117. data/core/vendor/src/crfsuite/Makefile.in +783 -0
  118. data/core/vendor/src/crfsuite/README +183 -0
  119. data/core/vendor/src/crfsuite/aclocal.m4 +9018 -0
  120. data/core/vendor/src/crfsuite/autogen.sh +38 -0
  121. data/core/vendor/src/crfsuite/compile +143 -0
  122. data/core/vendor/src/crfsuite/config.guess +1502 -0
  123. data/core/vendor/src/crfsuite/config.h.in +198 -0
  124. data/core/vendor/src/crfsuite/config.sub +1714 -0
  125. data/core/vendor/src/crfsuite/configure +14273 -0
  126. data/core/vendor/src/crfsuite/configure.in +149 -0
  127. data/core/vendor/src/crfsuite/crfsuite.sln +42 -0
  128. data/core/vendor/src/crfsuite/depcomp +630 -0
  129. data/core/vendor/src/crfsuite/example/chunking.py +49 -0
  130. data/core/vendor/src/crfsuite/example/crfutils.py +179 -0
  131. data/core/vendor/src/crfsuite/example/ner.py +270 -0
  132. data/core/vendor/src/crfsuite/example/pos.py +78 -0
  133. data/core/vendor/src/crfsuite/example/template.py +88 -0
  134. data/core/vendor/src/crfsuite/frontend/Makefile.am +29 -0
  135. data/core/vendor/src/crfsuite/frontend/Makefile.in +640 -0
  136. data/core/vendor/src/crfsuite/frontend/dump.c +116 -0
  137. data/core/vendor/src/crfsuite/frontend/frontend.vcxproj +129 -0
  138. data/core/vendor/src/crfsuite/frontend/iwa.c +273 -0
  139. data/core/vendor/src/crfsuite/frontend/iwa.h +65 -0
  140. data/core/vendor/src/crfsuite/frontend/learn.c +439 -0
  141. data/core/vendor/src/crfsuite/frontend/main.c +137 -0
  142. data/core/vendor/src/crfsuite/frontend/option.c +93 -0
  143. data/core/vendor/src/crfsuite/frontend/option.h +86 -0
  144. data/core/vendor/src/crfsuite/frontend/readdata.h +38 -0
  145. data/core/vendor/src/crfsuite/frontend/reader.c +136 -0
  146. data/core/vendor/src/crfsuite/frontend/tag.c +427 -0
  147. data/core/vendor/src/crfsuite/genbinary.sh.in +15 -0
  148. data/core/vendor/src/crfsuite/include/Makefile.am +11 -0
  149. data/core/vendor/src/crfsuite/include/Makefile.in +461 -0
  150. data/core/vendor/src/crfsuite/include/crfsuite.h +1063 -0
  151. data/core/vendor/src/crfsuite/include/crfsuite.hpp +555 -0
  152. data/core/vendor/src/crfsuite/include/crfsuite_api.hpp +400 -0
  153. data/core/vendor/src/crfsuite/include/os.h +61 -0
  154. data/core/vendor/src/crfsuite/install-sh +520 -0
  155. data/core/vendor/src/crfsuite/lib/cqdb/COPYING +28 -0
  156. data/core/vendor/src/crfsuite/lib/cqdb/Makefile.am +21 -0
  157. data/core/vendor/src/crfsuite/lib/cqdb/Makefile.in +549 -0
  158. data/core/vendor/src/crfsuite/lib/cqdb/cqdb.vcxproj +86 -0
  159. data/core/vendor/src/crfsuite/lib/cqdb/include/cqdb.h +524 -0
  160. data/core/vendor/src/crfsuite/lib/cqdb/src/cqdb.c +587 -0
  161. data/core/vendor/src/crfsuite/lib/cqdb/src/lookup3.c +976 -0
  162. data/core/vendor/src/crfsuite/lib/crf/Makefile.am +46 -0
  163. data/core/vendor/src/crfsuite/lib/crf/Makefile.in +721 -0
  164. data/core/vendor/src/crfsuite/lib/crf/crf.vcxproj +216 -0
  165. data/core/vendor/src/crfsuite/lib/crf/src/crf1d.h +353 -0
  166. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_context.c +705 -0
  167. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_encode.c +943 -0
  168. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_feature.c +352 -0
  169. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_model.c +994 -0
  170. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_tag.c +550 -0
  171. data/core/vendor/src/crfsuite/lib/crf/src/crfsuite.c +492 -0
  172. data/core/vendor/src/crfsuite/lib/crf/src/crfsuite_internal.h +236 -0
  173. data/core/vendor/src/crfsuite/lib/crf/src/crfsuite_train.c +272 -0
  174. data/core/vendor/src/crfsuite/lib/crf/src/dataset.c +106 -0
  175. data/core/vendor/src/crfsuite/lib/crf/src/dictionary.c +118 -0
  176. data/core/vendor/src/crfsuite/lib/crf/src/holdout.c +80 -0
  177. data/core/vendor/src/crfsuite/lib/crf/src/logging.c +91 -0
  178. data/core/vendor/src/crfsuite/lib/crf/src/logging.h +48 -0
  179. data/core/vendor/src/crfsuite/lib/crf/src/params.c +335 -0
  180. data/core/vendor/src/crfsuite/lib/crf/src/params.h +80 -0
  181. data/core/vendor/src/crfsuite/lib/crf/src/quark.c +172 -0
  182. data/core/vendor/src/crfsuite/lib/crf/src/quark.h +46 -0
  183. data/core/vendor/src/crfsuite/lib/crf/src/rumavl.c +1107 -0
  184. data/core/vendor/src/crfsuite/lib/crf/src/rumavl.h +160 -0
  185. data/core/vendor/src/crfsuite/lib/crf/src/train_arow.c +408 -0
  186. data/core/vendor/src/crfsuite/lib/crf/src/train_averaged_perceptron.c +242 -0
  187. data/core/vendor/src/crfsuite/lib/crf/src/train_l2sgd.c +507 -0
  188. data/core/vendor/src/crfsuite/lib/crf/src/train_lbfgs.c +338 -0
  189. data/core/vendor/src/crfsuite/lib/crf/src/train_passive_aggressive.c +435 -0
  190. data/core/vendor/src/crfsuite/lib/crf/src/vecmath.h +341 -0
  191. data/core/vendor/src/crfsuite/ltmain.sh +8413 -0
  192. data/core/vendor/src/crfsuite/missing +376 -0
  193. data/core/vendor/src/crfsuite/swig/Makefile.am +13 -0
  194. data/core/vendor/src/crfsuite/swig/Makefile.in +365 -0
  195. data/core/vendor/src/crfsuite/swig/crfsuite.cpp +2 -0
  196. data/core/vendor/src/crfsuite/swig/export.i +32 -0
  197. data/core/vendor/src/crfsuite/swig/python/README +92 -0
  198. data/core/vendor/src/crfsuite/swig/python/crfsuite.py +329 -0
  199. data/core/vendor/src/crfsuite/swig/python/export_wrap.cpp +14355 -0
  200. data/core/vendor/src/crfsuite/swig/python/export_wrap.h +63 -0
  201. data/core/vendor/src/crfsuite/swig/python/prepare.sh +9 -0
  202. data/core/vendor/src/crfsuite/swig/python/sample_tag.py +52 -0
  203. data/core/vendor/src/crfsuite/swig/python/sample_train.py +68 -0
  204. data/core/vendor/src/crfsuite/swig/python/setup.py +44 -0
  205. data/core/vendor/src/crfsuite/win32/stdint.h +679 -0
  206. data/core/vendor/src/liblbfgs/AUTHORS +1 -0
  207. data/core/vendor/src/liblbfgs/COPYING +22 -0
  208. data/core/vendor/src/liblbfgs/ChangeLog +120 -0
  209. data/core/vendor/src/liblbfgs/INSTALL +231 -0
  210. data/core/vendor/src/liblbfgs/Makefile.am +10 -0
  211. data/core/vendor/src/liblbfgs/Makefile.in +638 -0
  212. data/core/vendor/src/liblbfgs/NEWS +0 -0
  213. data/core/vendor/src/liblbfgs/README +71 -0
  214. data/core/vendor/src/liblbfgs/aclocal.m4 +6985 -0
  215. data/core/vendor/src/liblbfgs/autogen.sh +38 -0
  216. data/core/vendor/src/liblbfgs/config.guess +1411 -0
  217. data/core/vendor/src/liblbfgs/config.h.in +64 -0
  218. data/core/vendor/src/liblbfgs/config.sub +1500 -0
  219. data/core/vendor/src/liblbfgs/configure +21146 -0
  220. data/core/vendor/src/liblbfgs/configure.in +107 -0
  221. data/core/vendor/src/liblbfgs/depcomp +522 -0
  222. data/core/vendor/src/liblbfgs/include/lbfgs.h +745 -0
  223. data/core/vendor/src/liblbfgs/install-sh +322 -0
  224. data/core/vendor/src/liblbfgs/lbfgs.sln +26 -0
  225. data/core/vendor/src/liblbfgs/lib/Makefile.am +24 -0
  226. data/core/vendor/src/liblbfgs/lib/Makefile.in +499 -0
  227. data/core/vendor/src/liblbfgs/lib/arithmetic_ansi.h +133 -0
  228. data/core/vendor/src/liblbfgs/lib/arithmetic_sse_double.h +294 -0
  229. data/core/vendor/src/liblbfgs/lib/arithmetic_sse_float.h +298 -0
  230. data/core/vendor/src/liblbfgs/lib/lbfgs.c +1371 -0
  231. data/core/vendor/src/liblbfgs/lib/lib.vcxproj +95 -0
  232. data/core/vendor/src/liblbfgs/ltmain.sh +6426 -0
  233. data/core/vendor/src/liblbfgs/missing +353 -0
  234. data/core/vendor/src/liblbfgs/sample/Makefile.am +15 -0
  235. data/core/vendor/src/liblbfgs/sample/Makefile.in +433 -0
  236. data/core/vendor/src/liblbfgs/sample/sample.c +81 -0
  237. data/core/vendor/src/liblbfgs/sample/sample.cpp +126 -0
  238. data/core/vendor/src/liblbfgs/sample/sample.vcxproj +105 -0
  239. data/core/vendor/src/svm_light/LICENSE.txt +59 -0
  240. data/core/vendor/src/svm_light/Makefile +105 -0
  241. data/core/vendor/src/svm_light/kernel.h +40 -0
  242. data/core/vendor/src/svm_light/svm_classify.c +197 -0
  243. data/core/vendor/src/svm_light/svm_common.c +985 -0
  244. data/core/vendor/src/svm_light/svm_common.h +301 -0
  245. data/core/vendor/src/svm_light/svm_hideo.c +1062 -0
  246. data/core/vendor/src/svm_light/svm_learn.c +4147 -0
  247. data/core/vendor/src/svm_light/svm_learn.h +169 -0
  248. data/core/vendor/src/svm_light/svm_learn_main.c +397 -0
  249. data/core/vendor/src/svm_light/svm_loqo.c +211 -0
  250. data/ext/hack/Rakefile +17 -0
  251. data/ext/hack/support.rb +88 -0
  252. data/lib/opener/opinion_detectors/base.rb +112 -0
  253. data/lib/opener/opinion_detectors/base/version.rb +7 -0
  254. data/lib/opener/opinion_detectors/configuration_creator.rb +86 -0
  255. data/lib/opener/opinion_detectors/de.rb +7 -0
  256. data/lib/opener/opinion_detectors/en.rb +7 -0
  257. data/lib/opener/opinion_detectors/it.rb +7 -0
  258. data/lib/opener/opinion_detectors/nl.rb +6 -0
  259. data/opener-opinion-detector-base.gemspec +35 -0
  260. data/pre_build_requirements.txt +3 -0
  261. metadata +374 -0
@@ -0,0 +1,634 @@
1
+ #!/usr/bin/env python
2
+
3
+ import argparse
4
+ import sys
5
+ import ConfigParser
6
+ import os
7
+ import shutil
8
+ import time
9
+
10
+ from subprocess import Popen, PIPE
11
+ from generate_folds import generate_folds
12
+ from train import train_all
13
+ from classify_kaf_naf_file import tag_file_with_opinions
14
+ from KafNafParserPy import KafNafParser
15
+
16
+
17
+ ## CHANGES
18
+ # 1stApril2014 --> Included evaluation for the opinion miner basic
19
+
20
+ default_jar_file='/home/izquierdo/code/triple_evaluation/lib/TripleEvaluation-1.0-jar-with-dependencies.jar'
21
+ path_to_basic = '/home/izquierdo/opener_repos/opinion-detector-basic/core/opinion_detector_basic_multi.py'
22
+
23
+ '''
24
+ java -Xmx812m -cp $eval_jar_file \
25
+ vu.tripleevaluation.conversion.ConvertKafToTriples \
26
+ --kaf-file $1 --opinion
27
+ '''
28
+
29
+ def convert_to_triple(jar_file,input_file):
30
+ cmd = ['java -Xmx812m']
31
+ cmd.append('-cp')
32
+ cmd.append(jar_file)
33
+ cmd.append('vu.tripleevaluation.conversion.ConvertKafToTriples')
34
+ cmd.append('--kaf-file')
35
+ cmd.append(input_file)
36
+ cmd.append('--opinion')
37
+ converter = Popen(' '.join(cmd),shell=True, stderr=sys.stderr)
38
+ converter.wait()
39
+
40
+ '''
41
+ java -Xmx812m -cp $eval_jar_file \
42
+ vu.tripleevaluation.evaluation.EvaluateTriples \
43
+ --gold-standard-triples $1 \
44
+ --system-triples $2 --ignore-relation
45
+ '''
46
+
47
+ ## The output is generated in the same folder of the system_triples
48
+ ## with the extension .xls and .log
49
+ def evaluate_triples(jar_file,gold_triples,system_triples,evaluation_folder):
50
+ # We need to run it 3 times to
51
+ # 1) Get the prec/rec for opinion expression
52
+ # 2) Get the prec/rec for target
53
+ # 3) Get the prec/red for holder
54
+ runs = []
55
+ runs.append(([],'.expression'))
56
+ runs.append((['--element-second-filter','target'],'.target'))
57
+ runs.append((['--element-second-filter','holder:'],'.holder')) # The : is not an error!
58
+ for extra_opts, extension in runs:
59
+ cmd = ['java -Xmx812m']
60
+ cmd.append('-cp')
61
+ cmd.append(jar_file)
62
+ cmd.append('vu.tripleevaluation.evaluation.EvaluateTriples')
63
+ cmd.append('--gold-standard-triples')
64
+ cmd.append(gold_triples)
65
+ cmd.append('--system-triples')
66
+ cmd.append(system_triples)
67
+ cmd.extend(extra_opts)
68
+
69
+
70
+ converter = Popen(' '.join(cmd),shell=True, stderr=PIPE, stdout=PIPE)
71
+ converter.wait()
72
+
73
+ # The output must be on system_triples.trp and .log
74
+ # Move it to the evaluation folder with the proper extension
75
+ base_file = os.path.basename(system_triples).replace('.trp','')
76
+ shutil.move(system_triples+'.xls', evaluation_folder+'/'+base_file+extension)
77
+ shutil.move(system_triples+'.log', evaluation_folder+'/'+base_file+extension+'.log')
78
+
79
+
80
+ # This function reads all the opinions from the inputfile, maps the opinion labels
81
+ # with the mapped givenn in config_file:
82
+ # [valid_opinions]
83
+ #negative = Negative;StrongNegative
84
+ #positive = Positive;StrongPositive
85
+ #
86
+ # So all Negative,StrongNEgative are mapped to negative
87
+ # and writes the output to output_file
88
+ def map_opinion_labels(input_file,output_file,config_file):
89
+ # Load the mapping from the config_file
90
+ mapping = {}
91
+ parser = ConfigParser.ConfigParser()
92
+ parser.read(config_file)
93
+ for mapped_opinion, values_in_corpus in parser.items('valid_opinions'):
94
+ values = [ v for v in values_in_corpus.split(';') if v != '']
95
+ for v in values:
96
+ mapping[v] = mapped_opinion
97
+ del parser
98
+ ##################
99
+
100
+ input_kaf = KafNafParser(input_file)
101
+ remove_these = []
102
+ for opinion in input_kaf.get_opinions():
103
+ exp = opinion.get_expression()
104
+ polarity = exp.get_polarity()
105
+ if polarity in mapping:
106
+ mapped_polarity = mapping[polarity]
107
+ else:
108
+ opi_id = opinion.get_id()
109
+ remove_these.append(opi_id)
110
+ mapped_polarity = polarity
111
+
112
+ exp.set_polarity(mapped_polarity)
113
+
114
+ for opi_id in remove_these:
115
+ input_kaf.remove_this_opinion(opi_id)
116
+ input_kaf.dump(output_file)
117
+
118
+
119
+ def extract_figures(evaluation_file):
120
+ fic = open(evaluation_file)
121
+ prec_first = rec_first = prec_second = rec_second = prec_rel = rec_rel = 0
122
+ in_rel_section = False
123
+ for line in fic:
124
+ if line.find('Precision of first elements') != -1:
125
+ fields = line.strip().split('\t')
126
+ prec_first = fields[1]
127
+ if prec_first=='NaN': prec_first='0'
128
+ elif line.find('Recall of first elements') != -1:
129
+ fields = line.strip().split('\t')
130
+ rec_first = fields[1]
131
+ if rec_first=='NaN': rec_first='0'
132
+ if line.find('Precision of second elements') != -1:
133
+ fields = line.strip().split('\t')
134
+ prec_second = fields[1]
135
+ if prec_second=='NaN': prec_second='0'
136
+ elif line.find('Recall of second elements') != -1:
137
+ fields = line.strip().split('\t')
138
+ rec_second = fields[1]
139
+ if rec_second=='NaN': rec_second='0'
140
+ elif line.find('Results per relation') != -1:
141
+ in_rel_section = True
142
+ elif in_rel_section and line.startswith('Total'):
143
+ fields = line.strip().split('\t')
144
+ rec_rel = fields[-2]
145
+ prec_rel = fields[-1]
146
+ fic.close()
147
+ return float(prec_first)*100,float(rec_first)*100,float(prec_second)*100,float(rec_second)*100,float(prec_rel),float(rec_rel)
148
+
149
+
150
+ #This functions calls to the
151
+ def run_basic_version(input_file,output_file):
152
+ cmd = [path_to_basic]
153
+ cmd.append('--no-opinion-strength')
154
+ fin = open(input_file,'r')
155
+ fout = open(output_file,'w')
156
+ devnull = open(os.devnull,'wb')
157
+ basic_opinion_miner = Popen(' '.join(cmd),stdin=fin, stdout=fout,stderr=devnull,shell=True)
158
+ devnull.close()
159
+ fin.close()
160
+ basic_opinion_miner.wait()
161
+ fout.close()
162
+
163
+
164
+
165
+ if __name__ == '__main__':
166
+ #map_opinion_labels('input.kaf','output.kaf','models/hotel_set1_set2_nl_validation/fold_0/config.cfg')
167
+ #sys.exit(0)
168
+
169
+ import logging
170
+ logging.basicConfig(stream=sys.stderr,format='%(asctime)s - %(levelname)s\n %(message)s', level=logging.DEBUG)
171
+
172
+
173
+ argument_parser = argparse.ArgumentParser(description="Perform fold-cross validation on the opinion mining system")
174
+ argument_parser.add_argument('-n', type=int, default=10, dest='num_folds',help="Num folds (default 10)")
175
+ argument_parser.add_argument('--config_file','-f',dest='config_file', required=True, help='Configuration file')
176
+ argument_parser.add_argument('--eval_jar_file', action='store',dest='eval_jar_file', default=default_jar_file,help='Path to triple evaluation jar file (Default '+default_jar_file+')')
177
+ argument_parser.add_argument('-id',dest='exp_id',default='unknown',help='Experiment ID')
178
+ argument_parser.add_argument('-out_folds', dest='out_folds', type=argparse.FileType('wb'),)
179
+ arguments = argument_parser.parse_args()
180
+
181
+
182
+ ##
183
+ corpus_filename = None
184
+ output_folder = None
185
+ ##
186
+
187
+ ## Get the list of KAF files from the config filename
188
+ my_config = ConfigParser.ConfigParser()
189
+ my_config.read(arguments.config_file)
190
+
191
+ if not my_config.has_option('general', 'filename_training_list'):
192
+ print>>sys.stderr,'[general] => filename_training_list option missing in ',config_file
193
+ sys.exit(-1)
194
+
195
+ if not my_config.has_option('general','output_folder'):
196
+ print>>sys.stderr,'[general] => output_folder option missing in ',config_file
197
+ sys.exit(-1)
198
+
199
+ #This is the file with the list of KAF/NAf files for training
200
+ corpus_filename = my_config.get('general', 'filename_training_list')
201
+ output_folder = my_config.get('general','output_folder')
202
+
203
+
204
+ # Creating the folds in this way:
205
+ # output_folder/fold_[0-9]+
206
+
207
+ #With this we generate new folds and so on
208
+ generate_folds(corpus_filename,arguments.num_folds,output_folder)
209
+
210
+
211
+ ## With this we copy it from a referencre created split of folds
212
+ '''
213
+ reference = '/home/izquierdo/cltl_repos/opinion_miner_deluxe/models/hotel_nl_trainandtest_all'
214
+ if os.path.exists(output_folder):
215
+ shutil.rmtree(output_folder)
216
+ shutil.copytree(reference, output_folder)
217
+ '''
218
+
219
+
220
+ if arguments.out_folds is not None:
221
+ arguments.out_folds.write('\\begin{table}\n')
222
+ arguments.out_folds.write("\\begin{tabular}{c|c|c|c|c|c|c||c|c|c|c}\n")
223
+ arguments.out_folds.write("\\hline\n")
224
+ arguments.out_folds.write("Type & \\multicolumn{2}{|c|}{Expression} & \\multicolumn{2}{|c|}{Target} & \\multicolumn{2}{|c||}{Holder} &")
225
+ arguments.out_folds.write("\\multicolumn{2}{|c|}{Expression-Target} & \\multicolumn{2}{|c|}{Expression-Holder}\n")
226
+ arguments.out_folds.write("\\hline\n")
227
+ arguments.out_folds.write("& P & R & P & R & P & R & P & R & P & R \\\\\n")
228
+ arguments.out_folds.flush()
229
+ ## Process each fold
230
+
231
+ #For the deluxe
232
+ all_files = 0
233
+ all_p_e = all_r_e = all_p_t = all_r_t = all_p_h = all_r_h = all_p_e_t = all_r_e_t = all_p_e_h = all_r_e_h = 0
234
+
235
+ #For the basic
236
+ all_files_basic = 0
237
+ all_p_e_basic = all_r_e_basic = all_p_t_basic = all_r_t_basic = all_p_h_basic = all_r_h_basic = 0
238
+ all_p_e_t_basic = all_r_e_t_basic = all_p_e_h_basic = all_r_e_h_basic = 0
239
+ for num in range(arguments.num_folds):
240
+ this_folder = output_folder+'/fold_'+str(num)
241
+ this_model_folder = this_folder+'/models'
242
+ this_train_file = this_folder+'/train'
243
+ this_config = this_folder+'/config.cfg'
244
+ ##this_log = this_folder+'/train.log'
245
+
246
+ #Modifying the configuration and saving it to the proper file
247
+ my_config.set('general','output_folder',this_model_folder)
248
+ my_config.set('general', 'filename_training_list',this_train_file)
249
+ fp = open (this_config,'w')
250
+ my_config.write(fp)
251
+ fp.close()
252
+ ##################
253
+
254
+ # We need to run now the training for this folder
255
+ #def train_all(file_config):
256
+ print>>sys.stderr, 'Training'
257
+ print>>sys.stderr, ' Folder',this_folder,
258
+
259
+ this_pid = os.fork()
260
+ if this_pid == 0:
261
+ train_all(this_config)
262
+ sys.exit(0)
263
+ else:
264
+ while True:
265
+ sys.stderr.write('.')
266
+ sys.stderr.flush()
267
+ status = os.waitpid(this_pid,os.WNOHANG)
268
+ if status[0] != 0: break
269
+ time.sleep(1)
270
+
271
+ #####
272
+ ## Do the evaluation
273
+ ####
274
+
275
+
276
+ folder_out_kafs = this_folder+'/output_files'
277
+ if os.path.exists(folder_out_kafs):
278
+ shutil.rmtree(folder_out_kafs)
279
+ os.mkdir(folder_out_kafs)
280
+
281
+ folder_out_kafs_basic = this_folder+'/output_files_basic'
282
+ if os.path.exists(folder_out_kafs_basic):
283
+ shutil.rmtree(folder_out_kafs_basic)
284
+ os.mkdir(folder_out_kafs_basic)
285
+
286
+ folder_gold_triples = this_folder+'/gold_triples'
287
+ if os.path.exists(folder_gold_triples): shutil.rmtree(folder_gold_triples)
288
+ os.mkdir(folder_gold_triples)
289
+
290
+ fold_test_corpora = this_folder+'/test'
291
+ fold_test_corpora_desc = open(fold_test_corpora,'r')
292
+
293
+ evaluation_folder = this_folder+'/evaluation'
294
+ if os.path.exists(evaluation_folder):
295
+ shutil.rmtree(evaluation_folder)
296
+ os.mkdir(evaluation_folder)
297
+
298
+ evaluation_folder_basic = this_folder+'/evaluation_basic'
299
+ if os.path.exists(evaluation_folder_basic):
300
+ shutil.rmtree(evaluation_folder_basic)
301
+ os.mkdir(evaluation_folder_basic)
302
+
303
+ list_triple_files = [] #Pairs (gold,out)
304
+ list_test_base_files = []
305
+ for cnt, input_test_file in enumerate(fold_test_corpora_desc):
306
+ input_test_file = input_test_file.strip()
307
+ basename_file = os.path.basename(input_test_file)
308
+ list_test_base_files.append(basename_file)
309
+
310
+ # We copy the input KAF file into the gold triple folder doing a mapping
311
+ # of the opinion labels as the input might contain Positive, Negative, Strong
312
+ # and the output of the system just positive and neative (internal mapping)
313
+
314
+ map_opinion_labels(input_test_file,folder_gold_triples+'/'+basename_file,this_config)
315
+ print>>sys.stderr, cnt,'| Processing ',basename_file
316
+ sys.stderr.flush()
317
+
318
+ input_test_file = folder_gold_triples+'/'+basename_file
319
+ gold_triple_file = folder_gold_triples+'/'+basename_file+'.trp'
320
+
321
+
322
+ convert_to_triple(arguments.eval_jar_file, input_test_file)
323
+ print>>sys.stderr, ' Created triple gold in',os.path.basename(gold_triple_file)
324
+ sys.stderr.flush()
325
+
326
+ ##########################
327
+ #For the deluxe version #
328
+ ##########################
329
+ output_test_file = folder_out_kafs+'/'+basename_file
330
+ output_triple_file = folder_out_kafs+'/'+basename_file+'.trp'
331
+
332
+
333
+ tag_file_with_opinions(input_test_file,output_test_file,this_model_folder,remove_existing_opinions=True,include_polarity_strength=False)
334
+ print>>sys.stderr, ' Classified DELUXE in ',os.path.basename(output_test_file)
335
+ sys.stderr.flush()
336
+
337
+ convert_to_triple(arguments.eval_jar_file,output_test_file)
338
+ print>>sys.stderr, ' Created triple deluxe system in',os.path.basename(output_triple_file)
339
+ sys.stderr.flush()
340
+
341
+ # Run the evaluation
342
+ evaluate_triples(arguments.eval_jar_file, gold_triple_file, output_triple_file, evaluation_folder)
343
+ print>>sys.stderr, ' Evaluated deluxe on',evaluation_folder
344
+ sys.stderr.flush()
345
+ #########################
346
+
347
+ ##########################
348
+ #For the basic version #
349
+ ##########################
350
+ output_test_file_basic = folder_out_kafs_basic+'/'+basename_file
351
+ output_triple_file_basic = folder_out_kafs_basic+'/'+basename_file+'.trp'
352
+
353
+ #Call to the opinion miner basic and generate output_test_file_basic
354
+ print>>sys.stderr,' Start basic version input:',input_test_file,'out',output_test_file_basic
355
+ run_basic_version(input_test_file,output_test_file_basic)
356
+ print>>sys.stderr, ' Classified BASIC in ',os.path.basename(output_test_file_basic)
357
+ sys.stderr.flush()
358
+
359
+ convert_to_triple(arguments.eval_jar_file,output_test_file_basic)
360
+ print>>sys.stderr, ' Created triple basic system in',os.path.basename(output_triple_file_basic)
361
+ sys.stderr.flush()
362
+ # Run the evaluation
363
+ evaluate_triples(arguments.eval_jar_file, gold_triple_file, output_triple_file_basic, evaluation_folder_basic)
364
+ print>>sys.stderr, ' Evaluated basic on',evaluation_folder_basic
365
+ sys.stderr.flush()
366
+ #########################
367
+
368
+
369
+
370
+ fold_test_corpora_desc.close()
371
+
372
+ ## Extract the figures from the excel files
373
+ #DELUXE
374
+ num_files = 0
375
+ over_p_e = over_r_e = over_p_t = over_r_t = over_p_h = over_r_h = over_p_e_t = over_r_e_t = over_p_e_h = over_r_e_h = 0
376
+ for test_file in list_test_base_files:
377
+ expression_eval_file = evaluation_folder+'/'+test_file+'.expression'
378
+ target_eval_file = evaluation_folder+'/'+test_file+'.target'
379
+ holder_eval_file = evaluation_folder+'/'+test_file+'.holder'
380
+
381
+ prec_exp, rec_exp, _, _, _, _ = extract_figures(expression_eval_file)
382
+ _,_, prec_tar,rec_tar, prec_rel_exp_tar, rec_rel_exp_tar = extract_figures(target_eval_file)
383
+ _,_, prec_hol, rec_hol, prec_rel_exp_hol, rec_rel_exp_hol = extract_figures(holder_eval_file)
384
+
385
+ over_p_e += prec_exp
386
+ over_r_e += rec_exp
387
+ over_p_t += prec_tar
388
+ over_r_t += rec_tar
389
+ over_p_h += prec_hol
390
+ over_r_h += rec_hol
391
+ over_p_e_t += prec_rel_exp_tar
392
+ over_r_e_t += rec_rel_exp_tar
393
+ over_p_e_h += prec_rel_exp_hol
394
+ over_r_e_h += rec_rel_exp_hol
395
+ num_files += 1
396
+
397
+
398
+ #BASIC
399
+ num_files_basic = 0
400
+ over_p_e_basic = over_r_e_basic = over_p_t_basic = over_r_t_basic = over_p_h_basic = 0
401
+ over_r_h_basic = over_p_e_t_basic = over_r_e_t_basic = over_p_e_h_basic = over_r_e_h_basic = 0
402
+ for test_file in list_test_base_files:
403
+ expression_eval_file = evaluation_folder_basic+'/'+test_file+'.expression'
404
+ target_eval_file = evaluation_folder_basic+'/'+test_file+'.target'
405
+ holder_eval_file = evaluation_folder_basic+'/'+test_file+'.holder'
406
+
407
+ prec_exp, rec_exp, _, _, _, _ = extract_figures(expression_eval_file)
408
+ _,_, prec_tar,rec_tar, prec_rel_exp_tar, rec_rel_exp_tar = extract_figures(target_eval_file)
409
+ _,_, prec_hol, rec_hol, prec_rel_exp_hol, rec_rel_exp_hol = extract_figures(holder_eval_file)
410
+
411
+ over_p_e_basic += prec_exp
412
+ over_r_e_basic += rec_exp
413
+ over_p_t_basic += prec_tar
414
+ over_r_t_basic += rec_tar
415
+ over_p_h_basic += prec_hol
416
+ over_r_h_basic += rec_hol
417
+ over_p_e_t_basic += prec_rel_exp_tar
418
+ over_r_e_t_basic += rec_rel_exp_tar
419
+ over_p_e_h_basic += prec_rel_exp_hol
420
+ over_r_e_h_basic += rec_rel_exp_hol
421
+ num_files_basic += 1
422
+
423
+ if arguments.out_folds is not None:
424
+ arguments.out_folds.write("%s & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f\\\\\n" % ("Deluxe Fold "+str(num),
425
+ over_p_e*1.0/num_files,
426
+ over_r_e*1.0/num_files,
427
+ over_p_t*1.0/num_files,
428
+ over_r_t*1.0/num_files,
429
+ over_p_h*1.0/num_files,
430
+ over_r_h*1.0/num_files,
431
+ over_p_e_t*1.0/num_files,
432
+ over_r_e_t*1.0/num_files,
433
+ over_p_e_h*1.0/num_files,
434
+ over_r_e_h*1.0/num_files))
435
+ arguments.out_folds.write("%s & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f\\\\\n" % ("Basic Fold "+str(num),
436
+ over_p_e_basic*1.0/num_files_basic,
437
+ over_r_e_basic*1.0/num_files_basic,
438
+ over_p_t_basic*1.0/num_files_basic,
439
+ over_r_t_basic*1.0/num_files_basic,
440
+ over_p_h_basic*1.0/num_files_basic,
441
+ over_r_h_basic*1.0/num_files_basic,
442
+ over_p_e_t_basic*1.0/num_files_basic,
443
+ over_r_e_t_basic*1.0/num_files_basic,
444
+ over_p_e_h_basic*1.0/num_files_basic,
445
+ over_r_e_h_basic*1.0/num_files_basic
446
+ ))
447
+ arguments.out_folds.flush()
448
+
449
+
450
+
451
+ print>>sys.stderr
452
+ print>>sys.stderr, '#'*30
453
+ print>>sys.stderr, 'OVERALL DELUXE RESULTS FOR FOLD NUM',num
454
+ print>>sys.stderr, 'Num files:',num_files
455
+ print>>sys.stderr, ' Expression:'
456
+ print>>sys.stderr, ' Precision:',over_p_e*1.0/num_files
457
+ print>>sys.stderr, ' Recall: ',over_r_e*1.0/num_files
458
+ print>>sys.stderr, ' Target:'
459
+ print>>sys.stderr, ' Precision:',over_p_t*1.0/num_files
460
+ print>>sys.stderr, ' Recall: ',over_r_t*1.0/num_files
461
+ print>>sys.stderr, ' Holder:'
462
+ print>>sys.stderr, ' Precision:',over_p_h*1.0/num_files
463
+ print>>sys.stderr, ' Recall: ',over_r_h*1.0/num_files
464
+ print>>sys.stderr, ' Relation:'
465
+ print>>sys.stderr, ' Exp-Tar'
466
+ print>>sys.stderr, ' Prec:',over_p_e_t*1.0/num_files
467
+ print>>sys.stderr, ' Rec: ',over_r_e_t*1.0/num_files
468
+ print>>sys.stderr, ' Exp-Hol'
469
+ print>>sys.stderr, ' Prec:',over_p_e_h*1.0/num_files
470
+ print>>sys.stderr, ' Rec: ',over_r_e_h*1.0/num_files
471
+ print>>sys.stderr, '#'*30
472
+ all_files += num_files
473
+ all_p_e +=over_p_e
474
+ all_r_e += over_r_e
475
+ all_p_t += over_p_t
476
+ all_r_t += over_r_t
477
+ all_p_h += over_p_h
478
+ all_r_h += over_r_h
479
+ all_p_e_t += over_p_e_t
480
+ all_r_e_t += over_r_e_t
481
+ all_p_e_h += over_p_e_h
482
+ all_r_e_h += over_r_e_h
483
+
484
+ print>>sys.stderr
485
+ print>>sys.stderr, '#'*30
486
+ print>>sys.stderr, 'OVERALL BASIC RESULTS FOR FOLD NUM',num
487
+ print>>sys.stderr, 'Num files:',num_files_basic
488
+ print>>sys.stderr, ' Expression:'
489
+ print>>sys.stderr, ' Precision:',over_p_e_basic*1.0/num_files_basic
490
+ print>>sys.stderr, ' Recall: ',over_r_e_basic*1.0/num_files_basic
491
+ print>>sys.stderr, ' Target:'
492
+ print>>sys.stderr, ' Precision:',over_p_t_basic*1.0/num_files_basic
493
+ print>>sys.stderr, ' Recall: ',over_r_t_basic*1.0/num_files_basic
494
+ print>>sys.stderr, ' Holder:'
495
+ print>>sys.stderr, ' Precision:',over_p_h_basic*1.0/num_files_basic
496
+ print>>sys.stderr, ' Recall: ',over_r_h_basic*1.0/num_files_basic
497
+ print>>sys.stderr, ' Relation:'
498
+ print>>sys.stderr, ' Exp-Tar'
499
+ print>>sys.stderr, ' Prec:',over_p_e_t_basic*1.0/num_files_basic
500
+ print>>sys.stderr, ' Rec: ',over_r_e_t_basic*1.0/num_files_basic
501
+ print>>sys.stderr, ' Exp-Hol'
502
+ print>>sys.stderr, ' Prec:',over_p_e_h_basic*1.0/num_files_basic
503
+ print>>sys.stderr, ' Rec: ',over_r_e_h_basic*1.0/num_files_basic
504
+ print>>sys.stderr, '#'*30
505
+ print>>sys.stderr
506
+ all_files_basic += num_files_basic
507
+ all_p_e_basic +=over_p_e_basic
508
+ all_r_e_basic += over_r_e_basic
509
+ all_p_t_basic += over_p_t_basic
510
+ all_r_t_basic += over_r_t_basic
511
+ all_p_h_basic += over_p_h_basic
512
+ all_r_h_basic += over_r_h_basic
513
+ all_p_e_t_basic += over_p_e_t_basic
514
+ all_r_e_t_basic += over_r_e_t_basic
515
+ all_p_e_h_basic += over_p_e_h_basic
516
+ all_r_e_h_basic += over_r_e_h_basic
517
+ ##break ## JUST FOR ONE
518
+
519
+
520
+
521
+ ## NEXT FOLD!!!
522
+ print>>sys.stderr
523
+ print>>sys.stderr, '#'*30
524
+ print>>sys.stderr, 'FINAL DELUXE OVERALL RESULTS FOR ALL FOLDS (microaverage)'
525
+ print>>sys.stderr, 'Total Num files:',all_files
526
+ print>>sys.stderr, 'Total num folds:',num
527
+ print>>sys.stderr, ' Expression:'
528
+ print>>sys.stderr, ' Precision:',all_p_e*1.0/all_files
529
+ print>>sys.stderr, ' Recall: ',all_r_e*1.0/all_files
530
+ print>>sys.stderr, ' Target:'
531
+ print>>sys.stderr, ' Precision:',all_p_t*1.0/all_files
532
+ print>>sys.stderr, ' Recall: ',all_r_t*1.0/all_files
533
+ print>>sys.stderr, ' Holder:'
534
+ print>>sys.stderr, ' Precision:',all_p_h*1.0/all_files
535
+ print>>sys.stderr, ' Recall: ',all_r_h*1.0/all_files
536
+ print>>sys.stderr, ' Relation:'
537
+ print>>sys.stderr, ' Exp-Tar'
538
+ print>>sys.stderr, ' Prec:',all_p_e_t*1.0/all_files
539
+ print>>sys.stderr, ' Rec: ',all_r_e_t*1.0/all_files
540
+ print>>sys.stderr, ' Exp-Hol'
541
+ print>>sys.stderr, ' Prec:',all_p_e_h*1.0/all_files
542
+ print>>sys.stderr, ' Rec: ',all_r_e_h*1.0/all_files
543
+ print>>sys.stderr, '#'*30
544
+ print>>sys.stderr
545
+
546
+ print>>sys.stderr, 'LATEX DELUXE'
547
+ print>>sys.stderr, '\\begin{table}'
548
+ print>>sys.stderr, '\\begin{tabular}{c|c|c|}'
549
+ print>>sys.stderr, '\\hline'
550
+ print>>sys.stderr, 'Type & Precision & Recall\\\\'
551
+ print>>sys.stderr, '\\hline'
552
+ print>>sys.stderr, 'Expression & %.2f & %.2f\\\\' % (all_p_e*1.0/all_files,all_r_e*1.0/all_files)
553
+ print>>sys.stderr, 'Target & %.2f & %.2f \\\\' % (all_p_t*1.0/all_files,all_r_t*1.0/all_files)
554
+ print>>sys.stderr, 'Holder & %.2f & %.2f \\\\' % (all_p_h*1.0/all_files,all_r_h*1.0/all_files)
555
+ print>>sys.stderr, '\\hline'
556
+ print>>sys.stderr, 'Exp-Tar & %.2f & %.2f\\\\' % (all_p_e_t*1.0/all_files,all_r_e_t*1.0/all_files)
557
+ print>>sys.stderr, 'Exp-Hol & %.2f & %.2f\\\\' % (all_p_e_h*1.0/all_files,all_r_e_h*1.0/all_files)
558
+ print>>sys.stderr, '\\hline'
559
+ print>>sys.stderr, '\\end{tabular}'
560
+ print>>sys.stderr, '\\caption{Caption here}'
561
+ print>>sys.stderr, '\\end{table}'
562
+
563
+
564
+ print>>sys.stderr
565
+ print>>sys.stderr, '#'*30
566
+ print>>sys.stderr, 'FINAL OVERALL BASIC RESULTS FOR ALL FOLDS (microaverage)'
567
+ print>>sys.stderr, 'Total Num files:',all_files_basic
568
+ print>>sys.stderr, 'Total num folds:',num
569
+ print>>sys.stderr, ' Expression:'
570
+ print>>sys.stderr, ' Precision:',all_p_e_basic*1.0/all_files_basic
571
+ print>>sys.stderr, ' Recall: ',all_r_e_basic*1.0/all_files_basic
572
+ print>>sys.stderr, ' Target:'
573
+ print>>sys.stderr, ' Precision:',all_p_t_basic*1.0/all_files_basic
574
+ print>>sys.stderr, ' Recall: ',all_r_t_basic*1.0/all_files_basic
575
+ print>>sys.stderr, ' Holder:'
576
+ print>>sys.stderr, ' Precision:',all_p_h_basic*1.0/all_files_basic
577
+ print>>sys.stderr, ' Recall: ',all_r_h_basic*1.0/all_files_basic
578
+ print>>sys.stderr, ' Relation:'
579
+ print>>sys.stderr, ' Exp-Tar'
580
+ print>>sys.stderr, ' Prec:',all_p_e_t_basic*1.0/all_files_basic
581
+ print>>sys.stderr, ' Rec: ',all_r_e_t_basic*1.0/all_files_basic
582
+ print>>sys.stderr, ' Exp-Hol'
583
+ print>>sys.stderr, ' Prec:',all_p_e_h_basic*1.0/all_files_basic
584
+ print>>sys.stderr, ' Rec: ',all_r_e_h_basic*1.0/all_files_basic
585
+ print>>sys.stderr, '#'*30
586
+ print>>sys.stderr
587
+
588
+ print>>sys.stderr, 'LATEX BASIC'
589
+ print>>sys.stderr, '\\begin{table}'
590
+ print>>sys.stderr, '\\begin{tabular}{c|c|c|}'
591
+ print>>sys.stderr, '\\hline'
592
+ print>>sys.stderr, 'Type & Precision & Recall\\\\'
593
+ print>>sys.stderr, '\\hline'
594
+ print>>sys.stderr, 'Expression & %.2f & %.2f\\\\' % (all_p_e_basic*1.0/all_files_basic,all_r_e_basic*1.0/all_files_basic)
595
+ print>>sys.stderr, 'Target & %.2f & %.2f \\\\' % (all_p_t_basic*1.0/all_files_basic,all_r_t_basic*1.0/all_files_basic)
596
+ print>>sys.stderr, 'Holder & %.2f & %.2f \\\\' % (all_p_h_basic*1.0/all_files_basic,all_r_h_basic*1.0/all_files_basic)
597
+ print>>sys.stderr, '\\hline'
598
+ print>>sys.stderr, 'Exp-Tar & %.2f & %.2f\\\\' % (all_p_e_t_basic*1.0/all_files_basic,all_r_e_t_basic*1.0/all_files_basic)
599
+ print>>sys.stderr, 'Exp-Hol & %.2f & %.2f\\\\' % (all_p_e_h_basic*1.0/all_files_basic,all_r_e_h_basic*1.0/all_files_basic)
600
+ print>>sys.stderr, '\\hline'
601
+ print>>sys.stderr, '\\end{tabular}'
602
+ print>>sys.stderr, '\\caption{Caption here}'
603
+ print>>sys.stderr, '\\end{table}'
604
+
605
+
606
+ if arguments.out_folds is not None:
607
+ arguments.out_folds.write("\\end{tabular}\n")
608
+ arguments.out_folds.write("\\end{table}\n")
609
+ arguments.out_folds.close()
610
+
611
+ ##Output for Latex
612
+ print "%s Deluxe & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f\\\\" % (arguments.exp_id,
613
+ all_p_e * 1.0 /all_files,all_r_e *1.0/all_files,
614
+ all_p_t * 1.0 /all_files,all_r_t *1.0/all_files,
615
+ all_p_h * 1.0 /all_files,all_r_h *1.0/all_files,
616
+ all_p_e_t * 1.0/all_files,all_r_e_t*1.0/all_files,
617
+ all_p_e_h * 1.0/all_files,all_r_e_h*1.0/all_files
618
+ )
619
+ print "%s Basic & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f & %.2f\\\\" % (arguments.exp_id,
620
+ all_p_e_basic *1.0/all_files_basic,all_r_e_basic *1.0/all_files_basic,
621
+ all_p_t_basic *1.0/all_files_basic,all_r_t_basic *1.0/all_files_basic,
622
+ all_p_h_basic *1.0/all_files_basic,all_r_h_basic *1.0/all_files_basic,
623
+ all_p_e_t_basic*1.0/all_files_basic,all_r_e_t_basic*1.0/all_files_basic,
624
+ all_p_e_h_basic*1.0/all_files_basic,all_r_e_h_basic*1.0/all_files_basic
625
+ )
626
+
627
+
628
+
629
+
630
+
631
+
632
+
633
+ sys.exit(0)
634
+