opener-opinion-detector-base 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +101 -0
- data/bin/opinion-detector-base +19 -0
- data/core/annotation.cfg.erb +9 -0
- data/core/packages/KafNafParser-1.4.tar.gz +0 -0
- data/core/packages/VUA_pylib-1.5.tar.gz +0 -0
- data/core/python-scripts/LICENSE +339 -0
- data/core/python-scripts/README.md +226 -0
- data/core/python-scripts/classify_kaf_naf_file.py +499 -0
- data/core/python-scripts/cross_validation.py +634 -0
- data/core/python-scripts/generate_folds.py +134 -0
- data/core/python-scripts/models.cfg +10 -0
- data/core/python-scripts/my_templates/README +33 -0
- data/core/python-scripts/my_templates/templates_exp.only0.txt +6 -0
- data/core/python-scripts/my_templates/templates_exp.pol0.txt +10 -0
- data/core/python-scripts/my_templates/templates_exp.red.txt +7 -0
- data/core/python-scripts/my_templates/templates_exp.txt +10 -0
- data/core/python-scripts/my_templates/templates_holder.only0.txt +11 -0
- data/core/python-scripts/my_templates/templates_holder.red.txt +9 -0
- data/core/python-scripts/my_templates/templates_holder.txt +10 -0
- data/core/python-scripts/my_templates/templates_target.only0.txt +11 -0
- data/core/python-scripts/my_templates/templates_target.red.txt +9 -0
- data/core/python-scripts/my_templates/templates_target.txt +10 -0
- data/core/python-scripts/run_all_experiments.sh +49 -0
- data/core/python-scripts/run_basic.py +20 -0
- data/core/python-scripts/run_experiment.sh +42 -0
- data/core/python-scripts/scripts/__init__.py +1 -0
- data/core/python-scripts/scripts/config_manager.py +314 -0
- data/core/python-scripts/scripts/crfutils.py +215 -0
- data/core/python-scripts/scripts/extract_feats_relations.py +295 -0
- data/core/python-scripts/scripts/extract_features.py +376 -0
- data/core/python-scripts/scripts/feats_to_crf.exp.py +105 -0
- data/core/python-scripts/scripts/lexicons.py +44 -0
- data/core/python-scripts/scripts/link_entities_distance.py +77 -0
- data/core/python-scripts/scripts/relation_classifier.py +250 -0
- data/core/python-scripts/train.py +566 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/PKG-INFO +10 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/SOURCES.txt +22 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/dependency_links.txt +1 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/installed-files.txt +47 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/top_level.txt +1 -0
- data/core/site-packages/pre_build/KafNafParser/KafNafParserMod.py +390 -0
- data/core/site-packages/pre_build/KafNafParser/KafNafParserMod.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/__init__.py +14 -0
- data/core/site-packages/pre_build/KafNafParser/__init__.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/constituency_data.py +125 -0
- data/core/site-packages/pre_build/KafNafParser/constituency_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/coreference_data.py +52 -0
- data/core/site-packages/pre_build/KafNafParser/coreference_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/dependency_data.py +78 -0
- data/core/site-packages/pre_build/KafNafParser/dependency_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/entity_data.py +59 -0
- data/core/site-packages/pre_build/KafNafParser/entity_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/external_references_data.py +41 -0
- data/core/site-packages/pre_build/KafNafParser/external_references_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/__init__.py +2 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/__init__.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/constituency.py +205 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/constituency.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/dependency.py +309 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/dependency.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/features_data.py +131 -0
- data/core/site-packages/pre_build/KafNafParser/features_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/header_data.py +127 -0
- data/core/site-packages/pre_build/KafNafParser/header_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/opinion_data.py +211 -0
- data/core/site-packages/pre_build/KafNafParser/opinion_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/references_data.py +23 -0
- data/core/site-packages/pre_build/KafNafParser/references_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/span_data.py +63 -0
- data/core/site-packages/pre_build/KafNafParser/span_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/term_data.py +111 -0
- data/core/site-packages/pre_build/KafNafParser/term_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/term_sentiment_data.py +42 -0
- data/core/site-packages/pre_build/KafNafParser/term_sentiment_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/text_data.py +99 -0
- data/core/site-packages/pre_build/KafNafParser/text_data.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/PKG-INFO +10 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/SOURCES.txt +14 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/dependency_links.txt +1 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/installed-files.txt +23 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/top_level.txt +1 -0
- data/core/site-packages/pre_build/VUA_pylib/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/common/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/common/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/common/common.py +28 -0
- data/core/site-packages/pre_build/VUA_pylib/common/common.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/corpus_reader/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/corpus_reader/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/corpus_reader/google_web_nl.py +156 -0
- data/core/site-packages/pre_build/VUA_pylib/corpus_reader/google_web_nl.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/io_utils/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/io_utils/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/io_utils/feature_file.py +121 -0
- data/core/site-packages/pre_build/VUA_pylib/io_utils/feature_file.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/lexicon/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/lexicon/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/lexicon/lexicon.py +72 -0
- data/core/site-packages/pre_build/VUA_pylib/lexicon/lexicon.pyc +0 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/PKG-INFO +10 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/SOURCES.txt +7 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/dependency_links.txt +1 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/installed-files.txt +11 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/top_level.txt +1 -0
- data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.py +165 -0
- data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.pyc +0 -0
- data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.py +439 -0
- data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.pyc +0 -0
- data/core/site-packages/pre_build/VUKafParserPy/__init__.py +7 -0
- data/core/site-packages/pre_build/VUKafParserPy/__init__.pyc +0 -0
- data/core/vendor/src/crfsuite/AUTHORS +1 -0
- data/core/vendor/src/crfsuite/COPYING +27 -0
- data/core/vendor/src/crfsuite/ChangeLog +103 -0
- data/core/vendor/src/crfsuite/INSTALL +236 -0
- data/core/vendor/src/crfsuite/Makefile.am +19 -0
- data/core/vendor/src/crfsuite/Makefile.in +783 -0
- data/core/vendor/src/crfsuite/README +183 -0
- data/core/vendor/src/crfsuite/aclocal.m4 +9018 -0
- data/core/vendor/src/crfsuite/autogen.sh +38 -0
- data/core/vendor/src/crfsuite/compile +143 -0
- data/core/vendor/src/crfsuite/config.guess +1502 -0
- data/core/vendor/src/crfsuite/config.h.in +198 -0
- data/core/vendor/src/crfsuite/config.sub +1714 -0
- data/core/vendor/src/crfsuite/configure +14273 -0
- data/core/vendor/src/crfsuite/configure.in +149 -0
- data/core/vendor/src/crfsuite/crfsuite.sln +42 -0
- data/core/vendor/src/crfsuite/depcomp +630 -0
- data/core/vendor/src/crfsuite/example/chunking.py +49 -0
- data/core/vendor/src/crfsuite/example/crfutils.py +179 -0
- data/core/vendor/src/crfsuite/example/ner.py +270 -0
- data/core/vendor/src/crfsuite/example/pos.py +78 -0
- data/core/vendor/src/crfsuite/example/template.py +88 -0
- data/core/vendor/src/crfsuite/frontend/Makefile.am +29 -0
- data/core/vendor/src/crfsuite/frontend/Makefile.in +640 -0
- data/core/vendor/src/crfsuite/frontend/dump.c +116 -0
- data/core/vendor/src/crfsuite/frontend/frontend.vcxproj +129 -0
- data/core/vendor/src/crfsuite/frontend/iwa.c +273 -0
- data/core/vendor/src/crfsuite/frontend/iwa.h +65 -0
- data/core/vendor/src/crfsuite/frontend/learn.c +439 -0
- data/core/vendor/src/crfsuite/frontend/main.c +137 -0
- data/core/vendor/src/crfsuite/frontend/option.c +93 -0
- data/core/vendor/src/crfsuite/frontend/option.h +86 -0
- data/core/vendor/src/crfsuite/frontend/readdata.h +38 -0
- data/core/vendor/src/crfsuite/frontend/reader.c +136 -0
- data/core/vendor/src/crfsuite/frontend/tag.c +427 -0
- data/core/vendor/src/crfsuite/genbinary.sh.in +15 -0
- data/core/vendor/src/crfsuite/include/Makefile.am +11 -0
- data/core/vendor/src/crfsuite/include/Makefile.in +461 -0
- data/core/vendor/src/crfsuite/include/crfsuite.h +1063 -0
- data/core/vendor/src/crfsuite/include/crfsuite.hpp +555 -0
- data/core/vendor/src/crfsuite/include/crfsuite_api.hpp +400 -0
- data/core/vendor/src/crfsuite/include/os.h +61 -0
- data/core/vendor/src/crfsuite/install-sh +520 -0
- data/core/vendor/src/crfsuite/lib/cqdb/COPYING +28 -0
- data/core/vendor/src/crfsuite/lib/cqdb/Makefile.am +21 -0
- data/core/vendor/src/crfsuite/lib/cqdb/Makefile.in +549 -0
- data/core/vendor/src/crfsuite/lib/cqdb/cqdb.vcxproj +86 -0
- data/core/vendor/src/crfsuite/lib/cqdb/include/cqdb.h +524 -0
- data/core/vendor/src/crfsuite/lib/cqdb/src/cqdb.c +587 -0
- data/core/vendor/src/crfsuite/lib/cqdb/src/lookup3.c +976 -0
- data/core/vendor/src/crfsuite/lib/crf/Makefile.am +46 -0
- data/core/vendor/src/crfsuite/lib/crf/Makefile.in +721 -0
- data/core/vendor/src/crfsuite/lib/crf/crf.vcxproj +216 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d.h +353 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_context.c +705 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_encode.c +943 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_feature.c +352 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_model.c +994 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_tag.c +550 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crfsuite.c +492 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crfsuite_internal.h +236 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crfsuite_train.c +272 -0
- data/core/vendor/src/crfsuite/lib/crf/src/dataset.c +106 -0
- data/core/vendor/src/crfsuite/lib/crf/src/dictionary.c +118 -0
- data/core/vendor/src/crfsuite/lib/crf/src/holdout.c +80 -0
- data/core/vendor/src/crfsuite/lib/crf/src/logging.c +91 -0
- data/core/vendor/src/crfsuite/lib/crf/src/logging.h +48 -0
- data/core/vendor/src/crfsuite/lib/crf/src/params.c +335 -0
- data/core/vendor/src/crfsuite/lib/crf/src/params.h +80 -0
- data/core/vendor/src/crfsuite/lib/crf/src/quark.c +172 -0
- data/core/vendor/src/crfsuite/lib/crf/src/quark.h +46 -0
- data/core/vendor/src/crfsuite/lib/crf/src/rumavl.c +1107 -0
- data/core/vendor/src/crfsuite/lib/crf/src/rumavl.h +160 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_arow.c +408 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_averaged_perceptron.c +242 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_l2sgd.c +507 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_lbfgs.c +338 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_passive_aggressive.c +435 -0
- data/core/vendor/src/crfsuite/lib/crf/src/vecmath.h +341 -0
- data/core/vendor/src/crfsuite/ltmain.sh +8413 -0
- data/core/vendor/src/crfsuite/missing +376 -0
- data/core/vendor/src/crfsuite/swig/Makefile.am +13 -0
- data/core/vendor/src/crfsuite/swig/Makefile.in +365 -0
- data/core/vendor/src/crfsuite/swig/crfsuite.cpp +2 -0
- data/core/vendor/src/crfsuite/swig/export.i +32 -0
- data/core/vendor/src/crfsuite/swig/python/README +92 -0
- data/core/vendor/src/crfsuite/swig/python/crfsuite.py +329 -0
- data/core/vendor/src/crfsuite/swig/python/export_wrap.cpp +14355 -0
- data/core/vendor/src/crfsuite/swig/python/export_wrap.h +63 -0
- data/core/vendor/src/crfsuite/swig/python/prepare.sh +9 -0
- data/core/vendor/src/crfsuite/swig/python/sample_tag.py +52 -0
- data/core/vendor/src/crfsuite/swig/python/sample_train.py +68 -0
- data/core/vendor/src/crfsuite/swig/python/setup.py +44 -0
- data/core/vendor/src/crfsuite/win32/stdint.h +679 -0
- data/core/vendor/src/liblbfgs/AUTHORS +1 -0
- data/core/vendor/src/liblbfgs/COPYING +22 -0
- data/core/vendor/src/liblbfgs/ChangeLog +120 -0
- data/core/vendor/src/liblbfgs/INSTALL +231 -0
- data/core/vendor/src/liblbfgs/Makefile.am +10 -0
- data/core/vendor/src/liblbfgs/Makefile.in +638 -0
- data/core/vendor/src/liblbfgs/NEWS +0 -0
- data/core/vendor/src/liblbfgs/README +71 -0
- data/core/vendor/src/liblbfgs/aclocal.m4 +6985 -0
- data/core/vendor/src/liblbfgs/autogen.sh +38 -0
- data/core/vendor/src/liblbfgs/config.guess +1411 -0
- data/core/vendor/src/liblbfgs/config.h.in +64 -0
- data/core/vendor/src/liblbfgs/config.sub +1500 -0
- data/core/vendor/src/liblbfgs/configure +21146 -0
- data/core/vendor/src/liblbfgs/configure.in +107 -0
- data/core/vendor/src/liblbfgs/depcomp +522 -0
- data/core/vendor/src/liblbfgs/include/lbfgs.h +745 -0
- data/core/vendor/src/liblbfgs/install-sh +322 -0
- data/core/vendor/src/liblbfgs/lbfgs.sln +26 -0
- data/core/vendor/src/liblbfgs/lib/Makefile.am +24 -0
- data/core/vendor/src/liblbfgs/lib/Makefile.in +499 -0
- data/core/vendor/src/liblbfgs/lib/arithmetic_ansi.h +133 -0
- data/core/vendor/src/liblbfgs/lib/arithmetic_sse_double.h +294 -0
- data/core/vendor/src/liblbfgs/lib/arithmetic_sse_float.h +298 -0
- data/core/vendor/src/liblbfgs/lib/lbfgs.c +1371 -0
- data/core/vendor/src/liblbfgs/lib/lib.vcxproj +95 -0
- data/core/vendor/src/liblbfgs/ltmain.sh +6426 -0
- data/core/vendor/src/liblbfgs/missing +353 -0
- data/core/vendor/src/liblbfgs/sample/Makefile.am +15 -0
- data/core/vendor/src/liblbfgs/sample/Makefile.in +433 -0
- data/core/vendor/src/liblbfgs/sample/sample.c +81 -0
- data/core/vendor/src/liblbfgs/sample/sample.cpp +126 -0
- data/core/vendor/src/liblbfgs/sample/sample.vcxproj +105 -0
- data/core/vendor/src/svm_light/LICENSE.txt +59 -0
- data/core/vendor/src/svm_light/Makefile +105 -0
- data/core/vendor/src/svm_light/kernel.h +40 -0
- data/core/vendor/src/svm_light/svm_classify.c +197 -0
- data/core/vendor/src/svm_light/svm_common.c +985 -0
- data/core/vendor/src/svm_light/svm_common.h +301 -0
- data/core/vendor/src/svm_light/svm_hideo.c +1062 -0
- data/core/vendor/src/svm_light/svm_learn.c +4147 -0
- data/core/vendor/src/svm_light/svm_learn.h +169 -0
- data/core/vendor/src/svm_light/svm_learn_main.c +397 -0
- data/core/vendor/src/svm_light/svm_loqo.c +211 -0
- data/ext/hack/Rakefile +17 -0
- data/ext/hack/support.rb +88 -0
- data/lib/opener/opinion_detectors/base.rb +112 -0
- data/lib/opener/opinion_detectors/base/version.rb +7 -0
- data/lib/opener/opinion_detectors/configuration_creator.rb +86 -0
- data/lib/opener/opinion_detectors/de.rb +7 -0
- data/lib/opener/opinion_detectors/en.rb +7 -0
- data/lib/opener/opinion_detectors/it.rb +7 -0
- data/lib/opener/opinion_detectors/nl.rb +6 -0
- data/opener-opinion-detector-base.gemspec +35 -0
- data/pre_build_requirements.txt +3 -0
- metadata +374 -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
|
data/ext/hack/support.rb
ADDED
@@ -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,112 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
require_relative 'base/version'
|
5
|
+
require_relative 'configuration_creator'
|
6
|
+
require_relative 'en'
|
7
|
+
require_relative 'nl'
|
8
|
+
require_relative 'de'
|
9
|
+
require_relative 'it'
|
10
|
+
|
11
|
+
module Opener
|
12
|
+
module OpinionDetectors
|
13
|
+
class ModelsMissing < StandardError; end
|
14
|
+
|
15
|
+
##
|
16
|
+
# The base Opinion detector that supports English and Dutch.
|
17
|
+
#
|
18
|
+
# @!attribute [r] args
|
19
|
+
# @return [Array]
|
20
|
+
#
|
21
|
+
# @!attribute [r] options
|
22
|
+
# @return [Hash]
|
23
|
+
#
|
24
|
+
class Base
|
25
|
+
attr_reader :args, :options, :conf_file, :models_path
|
26
|
+
|
27
|
+
##
|
28
|
+
# @param [Hash] options
|
29
|
+
#
|
30
|
+
# @option options [Array] :args Extra commandline arguments to use.
|
31
|
+
#
|
32
|
+
def initialize(options = {})
|
33
|
+
@args = options.delete(:args) || []
|
34
|
+
@options = options
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Builds the command used to execute the kernel.
|
39
|
+
#
|
40
|
+
# @param [Array] args Commandline arguments passed to the command.
|
41
|
+
#
|
42
|
+
def command
|
43
|
+
return "#{adjust_python_path} python -E -OO #{kernel} -m #{conf_file.path} #{args.join(' ')}"
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# Runs the command and returns the output of STDOUT, STDERR and the
|
48
|
+
# process information.
|
49
|
+
#
|
50
|
+
# @param [String] input The input to tag.
|
51
|
+
# @return [Array]
|
52
|
+
#
|
53
|
+
def run(input)
|
54
|
+
language = language(input)
|
55
|
+
conf = ConfigurationCreator.new(language)
|
56
|
+
@conf_file = conf.config_file_path
|
57
|
+
@models_path = conf.models_path
|
58
|
+
|
59
|
+
return capture(input)
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
##
|
65
|
+
# @return [String]
|
66
|
+
#
|
67
|
+
def adjust_python_path
|
68
|
+
site_packages = File.join(core_dir, 'site-packages')
|
69
|
+
|
70
|
+
return "env PYTHONPATH=#{site_packages}:$PYTHONPATH"
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# capture3 method doesn't work properly with Jruby, so
|
75
|
+
# this is a workaround
|
76
|
+
#
|
77
|
+
def capture(input)
|
78
|
+
return Open3.popen3(*command.split(" ")) {|i, o, e, t|
|
79
|
+
out_reader = Thread.new { o.read }
|
80
|
+
err_reader = Thread.new { e.read }
|
81
|
+
i.write input
|
82
|
+
i.close
|
83
|
+
[out_reader.value, err_reader.value, t.value]
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# @return [String]
|
89
|
+
#
|
90
|
+
def core_dir
|
91
|
+
return File.expand_path('../../../../core', __FILE__)
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# @return [String]
|
96
|
+
#
|
97
|
+
def kernel
|
98
|
+
return File.join(core_dir, 'python-scripts/classify_kaf_naf_file.py')
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# @return the language from the KAF
|
103
|
+
#
|
104
|
+
def language(input)
|
105
|
+
document = Nokogiri::XML(input)
|
106
|
+
language = document.at('KAF').attr('xml:lang')
|
107
|
+
|
108
|
+
return language
|
109
|
+
end
|
110
|
+
end # Base
|
111
|
+
end # OpinionDetectors
|
112
|
+
end # Opener
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
module Opener
|
5
|
+
module OpinionDetectors
|
6
|
+
class ConfigurationCreator
|
7
|
+
attr_reader :language
|
8
|
+
|
9
|
+
include ERB::Util
|
10
|
+
|
11
|
+
def initialize(language)
|
12
|
+
@language = language
|
13
|
+
end
|
14
|
+
|
15
|
+
def config_file_path
|
16
|
+
file = Tempfile.new('opinion-detector-config')
|
17
|
+
file.write(render)
|
18
|
+
file.close
|
19
|
+
|
20
|
+
return file
|
21
|
+
end
|
22
|
+
|
23
|
+
def render
|
24
|
+
ERB.new(template).result(binding)
|
25
|
+
end
|
26
|
+
|
27
|
+
def models_path
|
28
|
+
env_path = ENV["OPINION_DETECTOR_MODELS_PATH"]
|
29
|
+
if env_path.nil?
|
30
|
+
raise ModelsMissing, "Please provide an environment variable named
|
31
|
+
OPINION_DETECTOR_MODELS_PATH that contains the path to the models"
|
32
|
+
end
|
33
|
+
|
34
|
+
path = File.expand_path(language, env_path)
|
35
|
+
return path
|
36
|
+
end
|
37
|
+
|
38
|
+
def crfsuite_path
|
39
|
+
File.expand_path("../../../../core/vendor/build/bin/crfsuite",__FILE__)
|
40
|
+
end
|
41
|
+
|
42
|
+
def svm_learn_path
|
43
|
+
File.expand_path("../../../../core/vendor/build/bin/svm_learn", __FILE__)
|
44
|
+
end
|
45
|
+
|
46
|
+
def svm_classify_path
|
47
|
+
File.expand_path("../../../../core/vendor/build/bin/svm_classify", __FILE__)
|
48
|
+
end
|
49
|
+
|
50
|
+
def template
|
51
|
+
%{
|
52
|
+
[general]
|
53
|
+
output_folder = <%=models_path%>/hotel_cfg1
|
54
|
+
|
55
|
+
[feature_templates]
|
56
|
+
expression = <%=models_path%>/hotel_cfg1/feature_templates/feat_template_expr.txt
|
57
|
+
holder = <%=models_path%>/hotel_cfg1/feature_templates/feat_template_holder.txt
|
58
|
+
target = <%=models_path%>/hotel_cfg1/feature_templates/feat_template_target.txt
|
59
|
+
|
60
|
+
[valid_opinions]
|
61
|
+
negative = Negative;StrongNegative
|
62
|
+
positive = Positive;StrongPositive
|
63
|
+
|
64
|
+
[relation_features]
|
65
|
+
use_dependencies = True
|
66
|
+
use_training_lexicons = True
|
67
|
+
use_this_expression_lexicon = <%=models_path%>/hotel_cfg1/lexicons/polarity_lexicon.txt
|
68
|
+
use_this_target_lexicon = <%=models_path%>/hotel_cfg1/lexicons/target_lexicon.txt
|
69
|
+
use_tokens_lemmas = True
|
70
|
+
exp_tar_threshold = -0.75
|
71
|
+
exp_hol_threshold = -0.5
|
72
|
+
|
73
|
+
[crfsuite]
|
74
|
+
path_to_binary = <%= crfsuite_path %>
|
75
|
+
parameters = -a lbfgs
|
76
|
+
|
77
|
+
[svmlight]
|
78
|
+
path_to_binary_learn = <%= svm_learn_path %>
|
79
|
+
path_to_binary_classify = <%= svm_classify_path %>
|
80
|
+
parameters = -c 0.1
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|