opener-opinion-detector-basic 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +30 -0
  3. data/bin/opinion-detector-basic +19 -0
  4. data/bin/opinion-detector-basic-server +10 -0
  5. data/config.ru +4 -0
  6. data/core/opinion_detector_basic_multi.py +499 -0
  7. data/core/packages/KafNafParser-1.3.tar.gz +0 -0
  8. data/core/packages/VUA_pylib-1.4.tar.gz +0 -0
  9. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/PKG-INFO +10 -0
  10. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/SOURCES.txt +7 -0
  11. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/dependency_links.txt +1 -0
  12. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/installed-files.txt +11 -0
  13. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/top_level.txt +1 -0
  14. data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.py +165 -0
  15. data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.pyc +0 -0
  16. data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.py +439 -0
  17. data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.pyc +0 -0
  18. data/core/site-packages/pre_build/VUKafParserPy/__init__.py +7 -0
  19. data/core/site-packages/pre_build/VUKafParserPy/__init__.pyc +0 -0
  20. data/core/vendor/src/crfsuite/AUTHORS +1 -0
  21. data/core/vendor/src/crfsuite/COPYING +27 -0
  22. data/core/vendor/src/crfsuite/ChangeLog +103 -0
  23. data/core/vendor/src/crfsuite/INSTALL +236 -0
  24. data/core/vendor/src/crfsuite/Makefile.am +19 -0
  25. data/core/vendor/src/crfsuite/Makefile.in +783 -0
  26. data/core/vendor/src/crfsuite/README +183 -0
  27. data/core/vendor/src/crfsuite/aclocal.m4 +9018 -0
  28. data/core/vendor/src/crfsuite/autogen.sh +38 -0
  29. data/core/vendor/src/crfsuite/compile +143 -0
  30. data/core/vendor/src/crfsuite/config.guess +1502 -0
  31. data/core/vendor/src/crfsuite/config.h.in +198 -0
  32. data/core/vendor/src/crfsuite/config.sub +1714 -0
  33. data/core/vendor/src/crfsuite/configure +14273 -0
  34. data/core/vendor/src/crfsuite/configure.in +149 -0
  35. data/core/vendor/src/crfsuite/crfsuite.sln +42 -0
  36. data/core/vendor/src/crfsuite/depcomp +630 -0
  37. data/core/vendor/src/crfsuite/example/chunking.py +49 -0
  38. data/core/vendor/src/crfsuite/example/crfutils.py +179 -0
  39. data/core/vendor/src/crfsuite/example/ner.py +270 -0
  40. data/core/vendor/src/crfsuite/example/pos.py +78 -0
  41. data/core/vendor/src/crfsuite/example/template.py +88 -0
  42. data/core/vendor/src/crfsuite/frontend/Makefile.am +29 -0
  43. data/core/vendor/src/crfsuite/frontend/Makefile.in +640 -0
  44. data/core/vendor/src/crfsuite/frontend/dump.c +116 -0
  45. data/core/vendor/src/crfsuite/frontend/frontend.vcxproj +129 -0
  46. data/core/vendor/src/crfsuite/frontend/iwa.c +273 -0
  47. data/core/vendor/src/crfsuite/frontend/iwa.h +65 -0
  48. data/core/vendor/src/crfsuite/frontend/learn.c +439 -0
  49. data/core/vendor/src/crfsuite/frontend/main.c +137 -0
  50. data/core/vendor/src/crfsuite/frontend/option.c +93 -0
  51. data/core/vendor/src/crfsuite/frontend/option.h +86 -0
  52. data/core/vendor/src/crfsuite/frontend/readdata.h +38 -0
  53. data/core/vendor/src/crfsuite/frontend/reader.c +136 -0
  54. data/core/vendor/src/crfsuite/frontend/tag.c +427 -0
  55. data/core/vendor/src/crfsuite/genbinary.sh.in +15 -0
  56. data/core/vendor/src/crfsuite/include/Makefile.am +11 -0
  57. data/core/vendor/src/crfsuite/include/Makefile.in +461 -0
  58. data/core/vendor/src/crfsuite/include/crfsuite.h +1063 -0
  59. data/core/vendor/src/crfsuite/include/crfsuite.hpp +555 -0
  60. data/core/vendor/src/crfsuite/include/crfsuite_api.hpp +400 -0
  61. data/core/vendor/src/crfsuite/include/os.h +61 -0
  62. data/core/vendor/src/crfsuite/install-sh +520 -0
  63. data/core/vendor/src/crfsuite/lib/cqdb/COPYING +28 -0
  64. data/core/vendor/src/crfsuite/lib/cqdb/Makefile.am +21 -0
  65. data/core/vendor/src/crfsuite/lib/cqdb/Makefile.in +549 -0
  66. data/core/vendor/src/crfsuite/lib/cqdb/cqdb.vcxproj +86 -0
  67. data/core/vendor/src/crfsuite/lib/cqdb/include/cqdb.h +524 -0
  68. data/core/vendor/src/crfsuite/lib/cqdb/src/cqdb.c +587 -0
  69. data/core/vendor/src/crfsuite/lib/cqdb/src/lookup3.c +976 -0
  70. data/core/vendor/src/crfsuite/lib/crf/Makefile.am +46 -0
  71. data/core/vendor/src/crfsuite/lib/crf/Makefile.in +721 -0
  72. data/core/vendor/src/crfsuite/lib/crf/crf.vcxproj +216 -0
  73. data/core/vendor/src/crfsuite/lib/crf/src/crf1d.h +353 -0
  74. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_context.c +705 -0
  75. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_encode.c +943 -0
  76. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_feature.c +352 -0
  77. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_model.c +994 -0
  78. data/core/vendor/src/crfsuite/lib/crf/src/crf1d_tag.c +550 -0
  79. data/core/vendor/src/crfsuite/lib/crf/src/crfsuite.c +492 -0
  80. data/core/vendor/src/crfsuite/lib/crf/src/crfsuite_internal.h +236 -0
  81. data/core/vendor/src/crfsuite/lib/crf/src/crfsuite_train.c +272 -0
  82. data/core/vendor/src/crfsuite/lib/crf/src/dataset.c +106 -0
  83. data/core/vendor/src/crfsuite/lib/crf/src/dictionary.c +118 -0
  84. data/core/vendor/src/crfsuite/lib/crf/src/holdout.c +80 -0
  85. data/core/vendor/src/crfsuite/lib/crf/src/logging.c +91 -0
  86. data/core/vendor/src/crfsuite/lib/crf/src/logging.h +48 -0
  87. data/core/vendor/src/crfsuite/lib/crf/src/params.c +335 -0
  88. data/core/vendor/src/crfsuite/lib/crf/src/params.h +80 -0
  89. data/core/vendor/src/crfsuite/lib/crf/src/quark.c +172 -0
  90. data/core/vendor/src/crfsuite/lib/crf/src/quark.h +46 -0
  91. data/core/vendor/src/crfsuite/lib/crf/src/rumavl.c +1107 -0
  92. data/core/vendor/src/crfsuite/lib/crf/src/rumavl.h +160 -0
  93. data/core/vendor/src/crfsuite/lib/crf/src/train_arow.c +408 -0
  94. data/core/vendor/src/crfsuite/lib/crf/src/train_averaged_perceptron.c +242 -0
  95. data/core/vendor/src/crfsuite/lib/crf/src/train_l2sgd.c +507 -0
  96. data/core/vendor/src/crfsuite/lib/crf/src/train_lbfgs.c +338 -0
  97. data/core/vendor/src/crfsuite/lib/crf/src/train_passive_aggressive.c +435 -0
  98. data/core/vendor/src/crfsuite/lib/crf/src/vecmath.h +341 -0
  99. data/core/vendor/src/crfsuite/ltmain.sh +8413 -0
  100. data/core/vendor/src/crfsuite/missing +376 -0
  101. data/core/vendor/src/crfsuite/swig/Makefile.am +13 -0
  102. data/core/vendor/src/crfsuite/swig/Makefile.in +365 -0
  103. data/core/vendor/src/crfsuite/swig/crfsuite.cpp +2 -0
  104. data/core/vendor/src/crfsuite/swig/export.i +32 -0
  105. data/core/vendor/src/crfsuite/swig/python/README +92 -0
  106. data/core/vendor/src/crfsuite/swig/python/crfsuite.py +329 -0
  107. data/core/vendor/src/crfsuite/swig/python/export_wrap.cpp +14355 -0
  108. data/core/vendor/src/crfsuite/swig/python/export_wrap.h +63 -0
  109. data/core/vendor/src/crfsuite/swig/python/prepare.sh +9 -0
  110. data/core/vendor/src/crfsuite/swig/python/sample_tag.py +52 -0
  111. data/core/vendor/src/crfsuite/swig/python/sample_train.py +68 -0
  112. data/core/vendor/src/crfsuite/swig/python/setup.py +44 -0
  113. data/core/vendor/src/crfsuite/win32/stdint.h +679 -0
  114. data/core/vendor/src/liblbfgs/AUTHORS +1 -0
  115. data/core/vendor/src/liblbfgs/COPYING +22 -0
  116. data/core/vendor/src/liblbfgs/ChangeLog +120 -0
  117. data/core/vendor/src/liblbfgs/INSTALL +231 -0
  118. data/core/vendor/src/liblbfgs/Makefile.am +10 -0
  119. data/core/vendor/src/liblbfgs/Makefile.in +638 -0
  120. data/core/vendor/src/liblbfgs/NEWS +0 -0
  121. data/core/vendor/src/liblbfgs/README +71 -0
  122. data/core/vendor/src/liblbfgs/aclocal.m4 +6985 -0
  123. data/core/vendor/src/liblbfgs/autogen.sh +38 -0
  124. data/core/vendor/src/liblbfgs/config.guess +1411 -0
  125. data/core/vendor/src/liblbfgs/config.h.in +64 -0
  126. data/core/vendor/src/liblbfgs/config.sub +1500 -0
  127. data/core/vendor/src/liblbfgs/configure +21146 -0
  128. data/core/vendor/src/liblbfgs/configure.in +107 -0
  129. data/core/vendor/src/liblbfgs/depcomp +522 -0
  130. data/core/vendor/src/liblbfgs/include/lbfgs.h +745 -0
  131. data/core/vendor/src/liblbfgs/install-sh +322 -0
  132. data/core/vendor/src/liblbfgs/lbfgs.sln +26 -0
  133. data/core/vendor/src/liblbfgs/lib/Makefile.am +24 -0
  134. data/core/vendor/src/liblbfgs/lib/Makefile.in +499 -0
  135. data/core/vendor/src/liblbfgs/lib/arithmetic_ansi.h +133 -0
  136. data/core/vendor/src/liblbfgs/lib/arithmetic_sse_double.h +294 -0
  137. data/core/vendor/src/liblbfgs/lib/arithmetic_sse_float.h +298 -0
  138. data/core/vendor/src/liblbfgs/lib/lbfgs.c +1371 -0
  139. data/core/vendor/src/liblbfgs/lib/lib.vcxproj +95 -0
  140. data/core/vendor/src/liblbfgs/ltmain.sh +6426 -0
  141. data/core/vendor/src/liblbfgs/missing +353 -0
  142. data/core/vendor/src/liblbfgs/sample/Makefile.am +15 -0
  143. data/core/vendor/src/liblbfgs/sample/Makefile.in +433 -0
  144. data/core/vendor/src/liblbfgs/sample/sample.c +81 -0
  145. data/core/vendor/src/liblbfgs/sample/sample.cpp +126 -0
  146. data/core/vendor/src/liblbfgs/sample/sample.vcxproj +105 -0
  147. data/core/vendor/src/svm_light/LICENSE.txt +59 -0
  148. data/core/vendor/src/svm_light/Makefile +105 -0
  149. data/core/vendor/src/svm_light/kernel.h +40 -0
  150. data/core/vendor/src/svm_light/svm_classify.c +197 -0
  151. data/core/vendor/src/svm_light/svm_common.c +985 -0
  152. data/core/vendor/src/svm_light/svm_common.h +301 -0
  153. data/core/vendor/src/svm_light/svm_hideo.c +1062 -0
  154. data/core/vendor/src/svm_light/svm_learn.c +4147 -0
  155. data/core/vendor/src/svm_light/svm_learn.h +169 -0
  156. data/core/vendor/src/svm_light/svm_learn_main.c +397 -0
  157. data/core/vendor/src/svm_light/svm_loqo.c +211 -0
  158. data/ext/hack/Rakefile +17 -0
  159. data/ext/hack/support.rb +88 -0
  160. data/lib/opener/opinion_detector_basic.rb +91 -0
  161. data/lib/opener/opinion_detector_basic/public/markdown.css +284 -0
  162. data/lib/opener/opinion_detector_basic/server.rb +16 -0
  163. data/lib/opener/opinion_detector_basic/version.rb +5 -0
  164. data/lib/opener/opinion_detector_basic/views/index.erb +97 -0
  165. data/lib/opener/opinion_detector_basic/views/result.erb +15 -0
  166. data/opener-opinion-detector-basic.gemspec +36 -0
  167. data/pre_build_requirements.txt +1 -0
  168. metadata +309 -0
@@ -0,0 +1,211 @@
1
+ /***********************************************************************/
2
+ /* */
3
+ /* svm_loqo.c */
4
+ /* */
5
+ /* Interface to the PR_LOQO optimization package for SVM. */
6
+ /* */
7
+ /* Author: Thorsten Joachims */
8
+ /* Date: 19.07.99 */
9
+ /* */
10
+ /* Copyright (c) 1999 Universitaet Dortmund - All rights reserved */
11
+ /* */
12
+ /* This software is available for non-commercial use only. It must */
13
+ /* not be modified and distributed without prior permission of the */
14
+ /* author. The author is not responsible for implications from the */
15
+ /* use of this software. */
16
+ /* */
17
+ /***********************************************************************/
18
+
19
+ # include <math.h>
20
+ # include "pr_loqo/pr_loqo.h"
21
+ # include "svm_common.h"
22
+
23
+ /* Common Block Declarations */
24
+
25
+ long verbosity;
26
+
27
+ /* /////////////////////////////////////////////////////////////// */
28
+
29
+ # define DEF_PRECISION_LINEAR 1E-8
30
+ # define DEF_PRECISION_NONLINEAR 1E-14
31
+
32
+ double *optimize_qp();
33
+ double *primal=0,*dual=0;
34
+ double init_margin=0.15;
35
+ long init_iter=500,precision_violations=0;
36
+ double model_b;
37
+ double opt_precision=DEF_PRECISION_LINEAR;
38
+
39
+ /* /////////////////////////////////////////////////////////////// */
40
+
41
+ void *my_malloc();
42
+
43
+ double *optimize_qp(qp,epsilon_crit,nx,threshold,learn_parm)
44
+ QP *qp;
45
+ double *epsilon_crit;
46
+ long nx; /* Maximum number of variables in QP */
47
+ double *threshold;
48
+ LEARN_PARM *learn_parm;
49
+ /* start the optimizer and return the optimal values */
50
+ {
51
+ register long i,j,result;
52
+ double margin,obj_before,obj_after;
53
+ double sigdig,dist,epsilon_loqo;
54
+ int iter;
55
+
56
+ if(!primal) { /* allocate memory at first call */
57
+ primal=(double *)my_malloc(sizeof(double)*nx*3);
58
+ dual=(double *)my_malloc(sizeof(double)*(nx*2+1));
59
+ }
60
+
61
+ if(verbosity>=4) { /* really verbose */
62
+ printf("\n\n");
63
+ for(i=0;i<qp->opt_n;i++) {
64
+ printf("%f: ",qp->opt_g0[i]);
65
+ for(j=0;j<qp->opt_n;j++) {
66
+ printf("%f ",qp->opt_g[i*qp->opt_n+j]);
67
+ }
68
+ printf(": a%ld=%.10f < %f",i,qp->opt_xinit[i],qp->opt_up[i]);
69
+ printf(": y=%f\n",qp->opt_ce[i]);
70
+ }
71
+ for(j=0;j<qp->opt_m;j++) {
72
+ printf("EQ-%ld: %f*a0",j,qp->opt_ce[j]);
73
+ for(i=1;i<qp->opt_n;i++) {
74
+ printf(" + %f*a%ld",qp->opt_ce[i],i);
75
+ }
76
+ printf(" = %f\n\n",-qp->opt_ce0[0]);
77
+ }
78
+ }
79
+
80
+ obj_before=0; /* calculate objective before optimization */
81
+ for(i=0;i<qp->opt_n;i++) {
82
+ obj_before+=(qp->opt_g0[i]*qp->opt_xinit[i]);
83
+ obj_before+=(0.5*qp->opt_xinit[i]*qp->opt_xinit[i]*qp->opt_g[i*qp->opt_n+i]);
84
+ for(j=0;j<i;j++) {
85
+ obj_before+=(qp->opt_xinit[j]*qp->opt_xinit[i]*qp->opt_g[j*qp->opt_n+i]);
86
+ }
87
+ }
88
+
89
+ result=STILL_RUNNING;
90
+ qp->opt_ce0[0]*=(-1.0);
91
+ /* Run pr_loqo. If a run fails, try again with parameters which lead */
92
+ /* to a slower, but more robust setting. */
93
+ for(margin=init_margin,iter=init_iter;
94
+ (margin<=0.9999999) && (result!=OPTIMAL_SOLUTION);) {
95
+ sigdig=-log10(opt_precision);
96
+
97
+ result=pr_loqo((int)qp->opt_n,(int)qp->opt_m,
98
+ (double *)qp->opt_g0,(double *)qp->opt_g,
99
+ (double *)qp->opt_ce,(double *)qp->opt_ce0,
100
+ (double *)qp->opt_low,(double *)qp->opt_up,
101
+ (double *)primal,(double *)dual,
102
+ (int)(verbosity-2),
103
+ (double)sigdig,(int)iter,
104
+ (double)margin,(double)(qp->opt_up[0])/4.0,(int)0);
105
+
106
+ if(isnan(dual[0])) { /* check for choldc problem */
107
+ if(verbosity>=2) {
108
+ printf("NOTICE: Restarting PR_LOQO with more conservative parameters.\n");
109
+ }
110
+ if(init_margin<0.80) { /* become more conservative in general */
111
+ init_margin=(4.0*margin+1.0)/5.0;
112
+ }
113
+ margin=(margin+1.0)/2.0;
114
+ (opt_precision)*=10.0; /* reduce precision */
115
+ if(verbosity>=2) {
116
+ printf("NOTICE: Reducing precision of PR_LOQO.\n");
117
+ }
118
+ }
119
+ else if(result!=OPTIMAL_SOLUTION) {
120
+ iter+=2000;
121
+ init_iter+=10;
122
+ (opt_precision)*=10.0; /* reduce precision */
123
+ if(verbosity>=2) {
124
+ printf("NOTICE: Reducing precision of PR_LOQO due to (%ld).\n",result);
125
+ }
126
+ }
127
+ }
128
+
129
+ if(qp->opt_m) /* Thanks to Alex Smola for this hint */
130
+ model_b=dual[0];
131
+ else
132
+ model_b=0;
133
+
134
+ /* Check the precision of the alphas. If results of current optimization */
135
+ /* violate KT-Conditions, relax the epsilon on the bounds on alphas. */
136
+ epsilon_loqo=1E-10;
137
+ for(i=0;i<qp->opt_n;i++) {
138
+ dist=-model_b*qp->opt_ce[i];
139
+ dist+=(qp->opt_g0[i]+1.0);
140
+ for(j=0;j<i;j++) {
141
+ dist+=(primal[j]*qp->opt_g[j*qp->opt_n+i]);
142
+ }
143
+ for(j=i;j<qp->opt_n;j++) {
144
+ dist+=(primal[j]*qp->opt_g[i*qp->opt_n+j]);
145
+ }
146
+ /* printf("LOQO: a[%d]=%f, dist=%f, b=%f\n",i,primal[i],dist,dual[0]); */
147
+ if((primal[i]<(qp->opt_up[i]-epsilon_loqo)) && (dist < (1.0-(*epsilon_crit)))) {
148
+ epsilon_loqo=(qp->opt_up[i]-primal[i])*2.0;
149
+ }
150
+ else if((primal[i]>(0+epsilon_loqo)) && (dist > (1.0+(*epsilon_crit)))) {
151
+ epsilon_loqo=primal[i]*2.0;
152
+ }
153
+ }
154
+
155
+ for(i=0;i<qp->opt_n;i++) { /* clip alphas to bounds */
156
+ if(primal[i]<=(0+epsilon_loqo)) {
157
+ primal[i]=0;
158
+ }
159
+ else if(primal[i]>=(qp->opt_up[i]-epsilon_loqo)) {
160
+ primal[i]=qp->opt_up[i];
161
+ }
162
+ }
163
+
164
+ obj_after=0; /* calculate objective after optimization */
165
+ for(i=0;i<qp->opt_n;i++) {
166
+ obj_after+=(qp->opt_g0[i]*primal[i]);
167
+ obj_after+=(0.5*primal[i]*primal[i]*qp->opt_g[i*qp->opt_n+i]);
168
+ for(j=0;j<i;j++) {
169
+ obj_after+=(primal[j]*primal[i]*qp->opt_g[j*qp->opt_n+i]);
170
+ }
171
+ }
172
+
173
+ /* if optimizer returned NAN values, reset and retry with smaller */
174
+ /* working set. */
175
+ if(isnan(obj_after) || isnan(model_b)) {
176
+ for(i=0;i<qp->opt_n;i++) {
177
+ primal[i]=qp->opt_xinit[i];
178
+ }
179
+ model_b=0;
180
+ if(learn_parm->svm_maxqpsize>2) {
181
+ learn_parm->svm_maxqpsize--; /* decrease size of qp-subproblems */
182
+ }
183
+ }
184
+
185
+ if(obj_after >= obj_before) { /* check whether there was progress */
186
+ (opt_precision)/=100.0;
187
+ precision_violations++;
188
+ if(verbosity>=2) {
189
+ printf("NOTICE: Increasing Precision of PR_LOQO.\n");
190
+ }
191
+ }
192
+
193
+ if(precision_violations > 500) {
194
+ (*epsilon_crit)*=10.0;
195
+ precision_violations=0;
196
+ if(verbosity>=1) {
197
+ printf("\nWARNING: Relaxing epsilon on KT-Conditions.\n");
198
+ }
199
+ }
200
+
201
+ (*threshold)=model_b;
202
+
203
+ if(result!=OPTIMAL_SOLUTION) {
204
+ printf("\nERROR: PR_LOQO did not converge. \n");
205
+ return(qp->opt_xinit);
206
+ }
207
+ else {
208
+ return(primal);
209
+ }
210
+ }
211
+
data/ext/hack/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'rake'
2
+ require_relative 'support'
3
+
4
+ desc 'Verifies the requirements'
5
+ task :requirements do
6
+ verify_requirements
7
+ require_executable("make")
8
+ end
9
+
10
+ task :compile => :requirements do
11
+ compile_vendored_code
12
+ end
13
+
14
+ task :default => [:compile] do
15
+ # path = File.join(PYTHON_SITE_PACKAGES, 'pre_install')
16
+ # pip_install(PRE_INSTALL_REQUIREMENTS, path)
17
+ end
@@ -0,0 +1,88 @@
1
+ require 'opener/build-tools'
2
+
3
+ include Opener::BuildTools::Requirements
4
+ include Opener::BuildTools::Python
5
+ include Opener::BuildTools::Files
6
+
7
+ # Directory of the core
8
+ CORE_DIR = File.expand_path('../../../core', __FILE__)
9
+
10
+ # Directory where packages will be installed to.
11
+ PYTHON_SITE_PACKAGES = File.expand_path(
12
+ '../../../core/site-packages',
13
+ __FILE__
14
+ )
15
+
16
+ # Directory containing the temporary files.
17
+ TMP_DIRECTORY = File.expand_path('../../../tmp', __FILE__)
18
+
19
+ # Path to the pip requirements file used to install requirements before
20
+ # packaging the Gem.
21
+ PRE_BUILD_REQUIREMENTS = File.expand_path(
22
+ '../../../pre_build_requirements.txt',
23
+ __FILE__
24
+ )
25
+
26
+ # Path to the pip requirements file used to install requirements upon Gem
27
+ # installation.
28
+ PRE_INSTALL_REQUIREMENTS = File.expand_path(
29
+ '../../../pre_install_requirements.txt',
30
+ __FILE__
31
+ )
32
+
33
+ # Path to the vendor directory for C code.
34
+ VENDOR_DIRECTORY = File.expand_path('../../../core/vendor', __FILE__)
35
+
36
+ # Path to the directory to install vendored C code into.
37
+ VENDOR_BUILD_DIRECTORY = File.expand_path(
38
+ '../../../core/vendor/build',
39
+ __FILE__
40
+ )
41
+
42
+ # Path to the directory that contains the source C code to compile.
43
+ VENDOR_SRC_DIRECTORY = File.expand_path('../../../core/vendor/src', __FILE__)
44
+
45
+
46
+ ##
47
+ # Verifies the requirements to install thi Gem.
48
+ #
49
+ def verify_requirements
50
+ require_executable('python')
51
+ require_version('python', python_version, '2.6.0')
52
+ require_executable('pip')
53
+ require_version('pip', pip_version, '1.3.1')
54
+ end
55
+
56
+ ##
57
+ # Compiles C code in the current directory using `make`.
58
+ #
59
+ # @param [Array] args The arguments to pass to ./configure
60
+ #
61
+ def compile(*args)
62
+ sh "./configure #{args.join(' ')}"
63
+ sh 'make'
64
+ sh 'make install'
65
+ sh 'make distclean'
66
+ end
67
+
68
+ ##
69
+ # Compiles the C code found in src/vendor.
70
+ #
71
+ def compile_vendored_code
72
+ src = VENDOR_SRC_DIRECTORY
73
+ build = VENDOR_BUILD_DIRECTORY
74
+
75
+ Dir.chdir(File.join(src, "liblbfgs")) do
76
+ compile("--prefix=#{build}")
77
+ end
78
+
79
+ Dir.chdir(File.join(src, "crfsuite")) do
80
+ compile("--prefix=#{build}", "--with-liblbfgs=#{build}")
81
+ end
82
+
83
+ Dir.chdir(File.join(src, "svm_light")) do
84
+ sh 'make'
85
+ sh 'mv svm_classify svm_learn ../../build/bin'
86
+ sh 'make clean'
87
+ end
88
+ end
@@ -0,0 +1,91 @@
1
+ require 'open3'
2
+
3
+ require_relative 'opinion_detector_basic/version'
4
+
5
+ module Opener
6
+
7
+
8
+ ##
9
+ # The basic Opinion detector.
10
+ #
11
+ # @!attribute [r] args
12
+ # @return [Array]
13
+ # @!attribute [r] options
14
+ # @return [Hash]
15
+ #
16
+ class OpinionDetectorBasic
17
+ attr_reader :args, :options
18
+
19
+ def initialize(options = {})
20
+ @args = options.delete(:args) || []
21
+ @options = options
22
+ end
23
+
24
+ ##
25
+ # Builds the command used to execute the kernel.
26
+ #
27
+ # @param [Array] args Commandline arguments passed to the command.
28
+ #
29
+ def command
30
+ return "#{adjust_python_path} python -E -OO #{kernel} #{args.join(' ')}"
31
+ end
32
+
33
+ ##
34
+ # Runs the command and returns the output of STDOUT, STDERR and the
35
+ # process information.
36
+ #
37
+ # @param [String] input The input to tag.
38
+ # @return [Array]
39
+ #
40
+ def run(input)
41
+ capture(input)
42
+ end
43
+
44
+ protected
45
+ ##
46
+ # @return [String]
47
+ #
48
+ def adjust_python_path
49
+ site_packages = File.join(core_dir, 'site-packages')
50
+ "env PYTHONPATH=#{site_packages}:$PYTHONPATH"
51
+ end
52
+ ##
53
+ # capture3 method doesn't work properly with Jruby, so
54
+ # this is a workaround
55
+ #
56
+
57
+ def capture(input)
58
+ Open3.popen3(*command.split(" ")) {|i, o, e, t|
59
+ out_reader = Thread.new { o.read }
60
+ err_reader = Thread.new { e.read }
61
+ i.write input
62
+ i.close
63
+ [out_reader.value, err_reader.value, t.value]
64
+ }
65
+ end
66
+
67
+ ##
68
+ # @return [String]
69
+ #
70
+ def core_dir
71
+ return File.expand_path('../../../core', __FILE__)
72
+ end
73
+
74
+ ##
75
+ # @return [String]
76
+ #
77
+ def kernel
78
+ return File.join(core_dir, 'opinion_detector_basic_multi.py')
79
+ end
80
+
81
+ ##
82
+ # @return the language from the KAF
83
+ #
84
+ def language(input)
85
+ document = Nokogiri::XML(input)
86
+ language = document.at('KAF').attr('xml:lang')
87
+ return language
88
+ end
89
+
90
+ end # OpinionDetectorBasic
91
+ end # Opener
@@ -0,0 +1,284 @@
1
+
2
+ input[type="text"], textarea
3
+ {
4
+ width: 500px;
5
+ }
6
+
7
+ body {
8
+ font-family: Helvetica, arial, sans-serif;
9
+ font-size: 14px;
10
+ line-height: 1.6;
11
+ padding-top: 10px;
12
+ padding-bottom: 10px;
13
+ background-color: white;
14
+ padding: 30px; }
15
+
16
+ body > *:first-child {
17
+ margin-top: 0 !important; }
18
+ body > *:last-child {
19
+ margin-bottom: 0 !important; }
20
+
21
+ a {
22
+ color: #4183C4; }
23
+ a.absent {
24
+ color: #cc0000; }
25
+ a.anchor {
26
+ display: block;
27
+ padding-left: 30px;
28
+ margin-left: -30px;
29
+ cursor: pointer;
30
+ position: absolute;
31
+ top: 0;
32
+ left: 0;
33
+ bottom: 0; }
34
+
35
+ h1, h2, h3, h4, h5, h6 {
36
+ margin: 20px 0 10px;
37
+ padding: 0;
38
+ font-weight: bold;
39
+ -webkit-font-smoothing: antialiased;
40
+ cursor: text;
41
+ position: relative; }
42
+
43
+ h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor, h5:hover a.anchor, h6:hover a.anchor {
44
+ background: url("../../images/modules/styleguide/para.png") no-repeat 10px center;
45
+ text-decoration: none; }
46
+
47
+ h1 tt, h1 code {
48
+ font-size: inherit; }
49
+
50
+ h2 tt, h2 code {
51
+ font-size: inherit; }
52
+
53
+ h3 tt, h3 code {
54
+ font-size: inherit; }
55
+
56
+ h4 tt, h4 code {
57
+ font-size: inherit; }
58
+
59
+ h5 tt, h5 code {
60
+ font-size: inherit; }
61
+
62
+ h6 tt, h6 code {
63
+ font-size: inherit; }
64
+
65
+ h1 {
66
+ font-size: 28px;
67
+ color: black; }
68
+
69
+ h2 {
70
+ font-size: 24px;
71
+ border-bottom: 1px solid #cccccc;
72
+ color: black; }
73
+
74
+ h3 {
75
+ font-size: 18px; }
76
+
77
+ h4 {
78
+ font-size: 16px; }
79
+
80
+ h5 {
81
+ font-size: 14px; }
82
+
83
+ h6 {
84
+ color: #777777;
85
+ font-size: 14px; }
86
+
87
+ p, blockquote, ul, ol, dl, li, table, pre {
88
+ margin: 15px 0; }
89
+
90
+ hr {
91
+ background: transparent url("../../images/modules/pulls/dirty-shade.png") repeat-x 0 0;
92
+ border: 0 none;
93
+ color: #cccccc;
94
+ height: 4px;
95
+ padding: 0; }
96
+
97
+ body > h2:first-child {
98
+ margin-top: 0;
99
+ padding-top: 0; }
100
+ body > h1:first-child {
101
+ margin-top: 0;
102
+ padding-top: 0; }
103
+ body > h1:first-child + h2 {
104
+ margin-top: 0;
105
+ padding-top: 0; }
106
+ body > h3:first-child, body > h4:first-child, body > h5:first-child, body > h6:first-child {
107
+ margin-top: 0;
108
+ padding-top: 0; }
109
+
110
+ a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
111
+ margin-top: 0;
112
+ padding-top: 0; }
113
+
114
+ h1 p, h2 p, h3 p, h4 p, h5 p, h6 p {
115
+ margin-top: 0; }
116
+
117
+ li p.first {
118
+ display: inline-block; }
119
+
120
+ ul, ol {
121
+ padding-left: 30px; }
122
+
123
+ ul :first-child, ol :first-child {
124
+ margin-top: 0; }
125
+
126
+ ul :last-child, ol :last-child {
127
+ margin-bottom: 0; }
128
+
129
+ dl {
130
+ padding: 0; }
131
+ dl dt {
132
+ font-size: 14px;
133
+ font-weight: bold;
134
+ font-style: italic;
135
+ padding: 0;
136
+ margin: 15px 0 5px; }
137
+ dl dt:first-child {
138
+ padding: 0; }
139
+ dl dt > :first-child {
140
+ margin-top: 0; }
141
+ dl dt > :last-child {
142
+ margin-bottom: 0; }
143
+ dl dd {
144
+ margin: 0 0 15px;
145
+ padding: 0 15px; }
146
+ dl dd > :first-child {
147
+ margin-top: 0; }
148
+ dl dd > :last-child {
149
+ margin-bottom: 0; }
150
+
151
+ blockquote {
152
+ border-left: 4px solid #dddddd;
153
+ padding: 0 15px;
154
+ color: #777777; }
155
+ blockquote > :first-child {
156
+ margin-top: 0; }
157
+ blockquote > :last-child {
158
+ margin-bottom: 0; }
159
+
160
+ table {
161
+ padding: 0; }
162
+ table tr {
163
+ border-top: 1px solid #cccccc;
164
+ background-color: white;
165
+ margin: 0;
166
+ padding: 0; }
167
+ table tr:nth-child(2n) {
168
+ background-color: #f8f8f8; }
169
+ table tr th {
170
+ font-weight: bold;
171
+ border: 1px solid #cccccc;
172
+ text-align: left;
173
+ margin: 0;
174
+ padding: 6px 13px; }
175
+ table tr td {
176
+ border: 1px solid #cccccc;
177
+ text-align: left;
178
+ margin: 0;
179
+ padding: 6px 13px; }
180
+ table tr th :first-child, table tr td :first-child {
181
+ margin-top: 0; }
182
+ table tr th :last-child, table tr td :last-child {
183
+ margin-bottom: 0; }
184
+
185
+ img {
186
+ max-width: 100%; }
187
+
188
+ span.frame {
189
+ display: block;
190
+ overflow: hidden; }
191
+ span.frame > span {
192
+ border: 1px solid #dddddd;
193
+ display: block;
194
+ float: left;
195
+ overflow: hidden;
196
+ margin: 13px 0 0;
197
+ padding: 7px;
198
+ width: auto; }
199
+ span.frame span img {
200
+ display: block;
201
+ float: left; }
202
+ span.frame span span {
203
+ clear: both;
204
+ color: #333333;
205
+ display: block;
206
+ padding: 5px 0 0; }
207
+ span.align-center {
208
+ display: block;
209
+ overflow: hidden;
210
+ clear: both; }
211
+ span.align-center > span {
212
+ display: block;
213
+ overflow: hidden;
214
+ margin: 13px auto 0;
215
+ text-align: center; }
216
+ span.align-center span img {
217
+ margin: 0 auto;
218
+ text-align: center; }
219
+ span.align-right {
220
+ display: block;
221
+ overflow: hidden;
222
+ clear: both; }
223
+ span.align-right > span {
224
+ display: block;
225
+ overflow: hidden;
226
+ margin: 13px 0 0;
227
+ text-align: right; }
228
+ span.align-right span img {
229
+ margin: 0;
230
+ text-align: right; }
231
+ span.float-left {
232
+ display: block;
233
+ margin-right: 13px;
234
+ overflow: hidden;
235
+ float: left; }
236
+ span.float-left span {
237
+ margin: 13px 0 0; }
238
+ span.float-right {
239
+ display: block;
240
+ margin-left: 13px;
241
+ overflow: hidden;
242
+ float: right; }
243
+ span.float-right > span {
244
+ display: block;
245
+ overflow: hidden;
246
+ margin: 13px auto 0;
247
+ text-align: right; }
248
+
249
+ code, tt {
250
+ margin: 0 2px;
251
+ padding: 0 5px;
252
+ white-space: nowrap;
253
+ border: 1px solid #eaeaea;
254
+ background-color: #f8f8f8;
255
+ border-radius: 3px; }
256
+
257
+ pre code {
258
+ margin: 0;
259
+ padding: 0;
260
+ white-space: pre;
261
+ border: none;
262
+ background: transparent; }
263
+
264
+ .highlight pre {
265
+ background-color: #f8f8f8;
266
+ border: 1px solid #cccccc;
267
+ font-size: 13px;
268
+ line-height: 19px;
269
+ overflow: auto;
270
+ padding: 6px 10px;
271
+ border-radius: 3px; }
272
+
273
+ pre {
274
+ background-color: #f8f8f8;
275
+ border: 1px solid #cccccc;
276
+ font-size: 13px;
277
+ line-height: 19px;
278
+ overflow: auto;
279
+ padding: 6px 10px;
280
+ border-radius: 3px; }
281
+ pre code, pre tt {
282
+ background-color: transparent;
283
+ border: none; }
284
+