opener-opinion-detector-basic 1.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 +30 -0
- data/bin/opinion-detector-basic +19 -0
- data/bin/opinion-detector-basic-server +10 -0
- data/config.ru +4 -0
- data/core/opinion_detector_basic_multi.py +499 -0
- data/core/packages/KafNafParser-1.3.tar.gz +0 -0
- data/core/packages/VUA_pylib-1.4.tar.gz +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_detector_basic.rb +91 -0
- data/lib/opener/opinion_detector_basic/public/markdown.css +284 -0
- data/lib/opener/opinion_detector_basic/server.rb +16 -0
- data/lib/opener/opinion_detector_basic/version.rb +5 -0
- data/lib/opener/opinion_detector_basic/views/index.erb +97 -0
- data/lib/opener/opinion_detector_basic/views/result.erb +15 -0
- data/opener-opinion-detector-basic.gemspec +36 -0
- data/pre_build_requirements.txt +1 -0
- metadata +309 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
/*
|
2
|
+
* CRFsuite frontend.
|
3
|
+
*
|
4
|
+
* Copyright (c) 2007-2010, Naoaki Okazaki
|
5
|
+
* All rights reserved.
|
6
|
+
*
|
7
|
+
* Redistribution and use in source and binary forms, with or without
|
8
|
+
* modification, are permitted provided that the following conditions are met:
|
9
|
+
* * Redistributions of source code must retain the above copyright
|
10
|
+
* notice, this list of conditions and the following disclaimer.
|
11
|
+
* * Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in the
|
13
|
+
* documentation and/or other materials provided with the distribution.
|
14
|
+
* * Neither the names of the authors nor the names of its contributors
|
15
|
+
* may be used to endorse or promote products derived from this
|
16
|
+
* software without specific prior written permission.
|
17
|
+
*
|
18
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
22
|
+
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
23
|
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
24
|
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
25
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
26
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
27
|
+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
28
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
*/
|
30
|
+
|
31
|
+
/* $Id$ */
|
32
|
+
|
33
|
+
#include <os.h>
|
34
|
+
|
35
|
+
#include <stdio.h>
|
36
|
+
#include <stdlib.h>
|
37
|
+
#include <string.h>
|
38
|
+
#include "option.h"
|
39
|
+
#include <crfsuite.h>
|
40
|
+
|
41
|
+
#define APPLICATION_S "CRFSuite"
|
42
|
+
|
43
|
+
int main_learn(int argc, char *argv[], const char *argv0);
|
44
|
+
int main_tag(int argc, char *argv[], const char *argv0);
|
45
|
+
int main_dump(int argc, char *argv[], const char *argv0);
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
typedef struct {
|
50
|
+
int help; /**< Show help message and exit. */
|
51
|
+
|
52
|
+
FILE *fpi;
|
53
|
+
FILE *fpo;
|
54
|
+
FILE *fpe;
|
55
|
+
} option_t;
|
56
|
+
|
57
|
+
static void option_init(option_t* opt)
|
58
|
+
{
|
59
|
+
memset(opt, 0, sizeof(*opt));
|
60
|
+
}
|
61
|
+
|
62
|
+
static void option_finish(option_t* opt)
|
63
|
+
{
|
64
|
+
}
|
65
|
+
|
66
|
+
BEGIN_OPTION_MAP(parse_options, option_t)
|
67
|
+
|
68
|
+
ON_OPTION(SHORTOPT('h') || LONGOPT("help"))
|
69
|
+
opt->help = 1;
|
70
|
+
|
71
|
+
END_OPTION_MAP()
|
72
|
+
|
73
|
+
void show_copyright(FILE *fp)
|
74
|
+
{
|
75
|
+
fprintf(fp, APPLICATION_S " " CRFSUITE_VERSION " " CRFSUITE_COPYRIGHT "\n");
|
76
|
+
fprintf(fp, "\n");
|
77
|
+
}
|
78
|
+
|
79
|
+
static void show_usage(FILE *fp, const char *argv0)
|
80
|
+
{
|
81
|
+
fprintf(fp, "USAGE: %s <COMMAND> [OPTIONS]\n", argv0);
|
82
|
+
fprintf(fp, " COMMAND Command name to specify the processing\n");
|
83
|
+
fprintf(fp, " OPTIONS Arguments for the command (optional; command-specific)\n");
|
84
|
+
fprintf(fp, "\n");
|
85
|
+
fprintf(fp, "COMMAND:\n");
|
86
|
+
fprintf(fp, " learn Obtain a model from a training set of instances\n");
|
87
|
+
fprintf(fp, " tag Assign suitable labels to given instances by using a model\n");
|
88
|
+
fprintf(fp, " dump Output a model in a plain-text format\n");
|
89
|
+
fprintf(fp, "\n");
|
90
|
+
fprintf(fp, "For the usage of each command, specify -h option in the command argument.\n");
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
int main(int argc, char *argv[])
|
95
|
+
{
|
96
|
+
option_t opt;
|
97
|
+
int arg_used = 0;
|
98
|
+
const char *command = NULL;
|
99
|
+
const char *argv0 = argv[0];
|
100
|
+
FILE *fpi = stdin, *fpo = stdout, *fpe = stderr;
|
101
|
+
|
102
|
+
/* Parse the command-line option. */
|
103
|
+
option_init(&opt);
|
104
|
+
arg_used = option_parse(++argv, --argc, parse_options, &opt);
|
105
|
+
if (arg_used < 0) {
|
106
|
+
return 1;
|
107
|
+
}
|
108
|
+
|
109
|
+
/* Show the help message if specified. */
|
110
|
+
if (opt.help) {
|
111
|
+
show_copyright(fpo);
|
112
|
+
show_usage(fpo, argv0);
|
113
|
+
return 0;
|
114
|
+
}
|
115
|
+
|
116
|
+
/* Check whether a command is specified in the command-line. */
|
117
|
+
if (argc <= arg_used) {
|
118
|
+
fprintf(fpe, "ERROR: No command specified. See help (-h) for the usage.\n");
|
119
|
+
return 1;
|
120
|
+
}
|
121
|
+
|
122
|
+
/* Execute the command. */
|
123
|
+
command = argv[arg_used];
|
124
|
+
if (strcmp(command, "learn") == 0) {
|
125
|
+
show_copyright(fpo);
|
126
|
+
return main_learn(argc-arg_used, argv+arg_used, argv0);
|
127
|
+
} else if (strcmp(command, "tag") == 0) {
|
128
|
+
return main_tag(argc-arg_used, argv+arg_used, argv0);
|
129
|
+
} else if (strcmp(command, "dump") == 0) {
|
130
|
+
return main_dump(argc-arg_used, argv+arg_used, argv0);
|
131
|
+
} else {
|
132
|
+
fprintf(fpe, "ERROR: Unrecognized command (%s) specified.\n", command);
|
133
|
+
return 1;
|
134
|
+
}
|
135
|
+
|
136
|
+
return 0;
|
137
|
+
}
|
@@ -0,0 +1,93 @@
|
|
1
|
+
/*
|
2
|
+
* A parser for command-line options.
|
3
|
+
*
|
4
|
+
* Copyright (c) 2007-2010, Naoaki Okazaki
|
5
|
+
* All rights reserved.
|
6
|
+
*
|
7
|
+
* Redistribution and use in source and binary forms, with or without
|
8
|
+
* modification, are permitted provided that the following conditions are met:
|
9
|
+
* * Redistributions of source code must retain the above copyright
|
10
|
+
* notice, this list of conditions and the following disclaimer.
|
11
|
+
* * Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in the
|
13
|
+
* documentation and/or other materials provided with the distribution.
|
14
|
+
* * Neither the names of the authors nor the names of its contributors
|
15
|
+
* may be used to endorse or promote products derived from this
|
16
|
+
* software without specific prior written permission.
|
17
|
+
*
|
18
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
22
|
+
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
23
|
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
24
|
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
25
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
26
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
27
|
+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
28
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
*/
|
30
|
+
|
31
|
+
/* $Id$ */
|
32
|
+
|
33
|
+
#include <os.h>
|
34
|
+
#include <stdlib.h>
|
35
|
+
#include <string.h>
|
36
|
+
#include "option.h"
|
37
|
+
|
38
|
+
int option_parse(char * const argv[], int num_argv, option_handler_t handler, void *instance)
|
39
|
+
{
|
40
|
+
int i;
|
41
|
+
|
42
|
+
for (i = 0;i < num_argv;++i) {
|
43
|
+
const char *token = argv[i];
|
44
|
+
if (*token++ == '-') {
|
45
|
+
int ret = 0;
|
46
|
+
const char *next_token = (i+1 < num_argv) ? argv[i+1] : "";
|
47
|
+
if (!*token) {
|
48
|
+
break; /* Only '-' was found. */
|
49
|
+
} else if (*token == '-') {
|
50
|
+
const char *arg = strchr(++token, '=');
|
51
|
+
if (arg) {
|
52
|
+
arg++;
|
53
|
+
} else {
|
54
|
+
arg = next_token;
|
55
|
+
}
|
56
|
+
|
57
|
+
ret = handler(instance, 0, token, arg);
|
58
|
+
if (ret < 0) {
|
59
|
+
return -1;
|
60
|
+
}
|
61
|
+
if (arg == next_token) {
|
62
|
+
i += ret;
|
63
|
+
}
|
64
|
+
} else {
|
65
|
+
char c;
|
66
|
+
while ((c = *token++) != '\0') {
|
67
|
+
const char *arg = *token ? token : next_token;
|
68
|
+
ret = handler(instance, c, token, arg);
|
69
|
+
if (ret < 0) {
|
70
|
+
return -1;
|
71
|
+
}
|
72
|
+
if (ret > 0) {
|
73
|
+
if (arg == token) {
|
74
|
+
token = "";
|
75
|
+
} else {
|
76
|
+
i++;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
} /* while */
|
80
|
+
} /* else (*token == '-') */
|
81
|
+
} else {
|
82
|
+
break; /* a non-option argument was fonud. */
|
83
|
+
}
|
84
|
+
} /* for (i) */
|
85
|
+
|
86
|
+
return i;
|
87
|
+
}
|
88
|
+
|
89
|
+
int option_strcmp(const char *option, const char *longname)
|
90
|
+
{
|
91
|
+
const char *p = strchr(option, '=');
|
92
|
+
return p ? strncmp(option, longname, p-option) : strcmp(option, longname);
|
93
|
+
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
/*
|
2
|
+
* A parser for command-line options.
|
3
|
+
*
|
4
|
+
* Copyright (c) 2007-2010, Naoaki Okazaki
|
5
|
+
* All rights reserved.
|
6
|
+
*
|
7
|
+
* Redistribution and use in source and binary forms, with or without
|
8
|
+
* modification, are permitted provided that the following conditions are met:
|
9
|
+
* * Redistributions of source code must retain the above copyright
|
10
|
+
* notice, this list of conditions and the following disclaimer.
|
11
|
+
* * Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in the
|
13
|
+
* documentation and/or other materials provided with the distribution.
|
14
|
+
* * Neither the names of the authors nor the names of its contributors
|
15
|
+
* may be used to endorse or promote products derived from this
|
16
|
+
* software without specific prior written permission.
|
17
|
+
*
|
18
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
22
|
+
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
23
|
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
24
|
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
25
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
26
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
27
|
+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
28
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
*/
|
30
|
+
|
31
|
+
/* $Id$ */
|
32
|
+
|
33
|
+
#ifndef __OPTION_H__
|
34
|
+
#define __OPTION_H__
|
35
|
+
|
36
|
+
#ifdef __cplusplus
|
37
|
+
extern "C" {
|
38
|
+
#endif/*__cplusplus*/
|
39
|
+
|
40
|
+
typedef int (*option_handler_t)(void *instance, char c, const char *longname, const char *arg);
|
41
|
+
|
42
|
+
int option_parse(char * const argv[], int num_argv, option_handler_t handler, void *instance);
|
43
|
+
int option_strcmp(const char *option, const char *longname);
|
44
|
+
|
45
|
+
/** The begin of inline option map. */
|
46
|
+
#define BEGIN_OPTION_MAP(name, type) \
|
47
|
+
int name(void *instance, char __c, const char *__longname, const char *arg) \
|
48
|
+
{ \
|
49
|
+
int used_args = 0; \
|
50
|
+
type *opt = (type *)instance; \
|
51
|
+
if (0) { \
|
52
|
+
|
53
|
+
/** An entry of option map */
|
54
|
+
#define ON_OPTION(test) \
|
55
|
+
return used_args; \
|
56
|
+
} else if (test) { \
|
57
|
+
used_args = 0; \
|
58
|
+
|
59
|
+
#define ON_OPTION_WITH_ARG(test) \
|
60
|
+
return used_args; \
|
61
|
+
} else if (test) { \
|
62
|
+
used_args = 1; \
|
63
|
+
|
64
|
+
/** The end of option map implementation */
|
65
|
+
#define END_OPTION_MAP() \
|
66
|
+
return used_args; \
|
67
|
+
} \
|
68
|
+
if (__c != 0) { \
|
69
|
+
fprintf(stderr, "Unrecognized option -%c\n", __c); \
|
70
|
+
} else if (__longname != NULL) { \
|
71
|
+
fprintf(stderr, "Unrecognized option --%s\n", __longname); \
|
72
|
+
} \
|
73
|
+
return -1; \
|
74
|
+
} \
|
75
|
+
|
76
|
+
/** A predicator for short options */
|
77
|
+
#define SHORTOPT(x) (__c == x)
|
78
|
+
/** A predicator for long options */
|
79
|
+
#define LONGOPT(x) (!__c && option_strcmp(__longname, x) == 0)
|
80
|
+
|
81
|
+
#ifdef __cplusplus
|
82
|
+
}
|
83
|
+
#endif/*__cplusplus*/
|
84
|
+
|
85
|
+
#endif/*__OPTION_H__*/
|
86
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
/*
|
2
|
+
* Data reader.
|
3
|
+
*
|
4
|
+
* Copyright (c) 2007-2010, Naoaki Okazaki
|
5
|
+
* All rights reserved.
|
6
|
+
*
|
7
|
+
* Redistribution and use in source and binary forms, with or without
|
8
|
+
* modification, are permitted provided that the following conditions are met:
|
9
|
+
* * Redistributions of source code must retain the above copyright
|
10
|
+
* notice, this list of conditions and the following disclaimer.
|
11
|
+
* * Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in the
|
13
|
+
* documentation and/or other materials provided with the distribution.
|
14
|
+
* * Neither the names of the authors nor the names of its contributors
|
15
|
+
* may be used to endorse or promote products derived from this
|
16
|
+
* software without specific prior written permission.
|
17
|
+
*
|
18
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
22
|
+
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
23
|
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
24
|
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
25
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
26
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
27
|
+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
28
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
*/
|
30
|
+
|
31
|
+
/* $Id$ */
|
32
|
+
|
33
|
+
#ifndef __READDATA_H__
|
34
|
+
#define __READDATA_H__
|
35
|
+
|
36
|
+
int read_data(FILE *fpi, FILE *fpo, crfsuite_data_t* data, int group);
|
37
|
+
|
38
|
+
#endif/*__READDATA_H__*/
|
@@ -0,0 +1,136 @@
|
|
1
|
+
/*
|
2
|
+
* Data reader.
|
3
|
+
*
|
4
|
+
* Copyright (c) 2007-2010, Naoaki Okazaki
|
5
|
+
* All rights reserved.
|
6
|
+
*
|
7
|
+
* Redistribution and use in source and binary forms, with or without
|
8
|
+
* modification, are permitted provided that the following conditions are met:
|
9
|
+
* * Redistributions of source code must retain the above copyright
|
10
|
+
* notice, this list of conditions and the following disclaimer.
|
11
|
+
* * Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in the
|
13
|
+
* documentation and/or other materials provided with the distribution.
|
14
|
+
* * Neither the names of the authors nor the names of its contributors
|
15
|
+
* may be used to endorse or promote products derived from this
|
16
|
+
* software without specific prior written permission.
|
17
|
+
*
|
18
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
22
|
+
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
23
|
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
24
|
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
25
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
26
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
27
|
+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
28
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
*/
|
30
|
+
|
31
|
+
/* $Id$ */
|
32
|
+
|
33
|
+
#include <os.h>
|
34
|
+
|
35
|
+
#include <stdio.h>
|
36
|
+
#include <stdlib.h>
|
37
|
+
|
38
|
+
#include <crfsuite.h>
|
39
|
+
#include "iwa.h"
|
40
|
+
|
41
|
+
static int progress(FILE *fpo, int prev, int current)
|
42
|
+
{
|
43
|
+
while (prev < current) {
|
44
|
+
++prev;
|
45
|
+
if (prev % 2 == 0) {
|
46
|
+
if (prev % 10 == 0) {
|
47
|
+
fprintf(fpo, "%d", prev / 10);
|
48
|
+
fflush(fpo);
|
49
|
+
} else {
|
50
|
+
fprintf(fpo, ".", prev / 10);
|
51
|
+
fflush(fpo);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
return prev;
|
56
|
+
}
|
57
|
+
|
58
|
+
int read_data(FILE *fpi, FILE *fpo, crfsuite_data_t* data, int group)
|
59
|
+
{
|
60
|
+
int n = 0;
|
61
|
+
int lid = -1;
|
62
|
+
crfsuite_instance_t inst;
|
63
|
+
crfsuite_item_t item;
|
64
|
+
crfsuite_attribute_t cont;
|
65
|
+
iwa_t* iwa = NULL;
|
66
|
+
crfsuite_dictionary_t *attrs = data->attrs;
|
67
|
+
crfsuite_dictionary_t *labels = data->labels;
|
68
|
+
const iwa_token_t *token = NULL;
|
69
|
+
long filesize = 0, begin = 0, offset = 0;
|
70
|
+
int prev = 0, current = 0;
|
71
|
+
|
72
|
+
/* Initialize the instance.*/
|
73
|
+
crfsuite_instance_init(&inst);
|
74
|
+
inst.group = group;
|
75
|
+
|
76
|
+
/* Obtain the file size. */
|
77
|
+
begin = ftell(fpi);
|
78
|
+
fseek(fpi, 0, SEEK_END);
|
79
|
+
filesize = ftell(fpi) - begin;
|
80
|
+
fseek(fpi, begin, SEEK_SET);
|
81
|
+
|
82
|
+
/* */
|
83
|
+
fprintf(fpo, "0");
|
84
|
+
fflush(fpo);
|
85
|
+
prev = 0;
|
86
|
+
|
87
|
+
iwa = iwa_reader(fpi);
|
88
|
+
while (token = iwa_read(iwa), token != NULL) {
|
89
|
+
/* Progress report. */
|
90
|
+
offset = ftell(fpi);
|
91
|
+
current = (int)((offset - begin) * 100.0 / (double)filesize);
|
92
|
+
prev = progress(fpo, prev, current);
|
93
|
+
|
94
|
+
switch (token->type) {
|
95
|
+
case IWA_BOI:
|
96
|
+
/* Initialize an item. */
|
97
|
+
lid = -1;
|
98
|
+
crfsuite_item_init(&item);
|
99
|
+
break;
|
100
|
+
case IWA_EOI:
|
101
|
+
/* Append the item to the instance. */
|
102
|
+
if (0 <= lid) {
|
103
|
+
crfsuite_instance_append(&inst, &item, lid);
|
104
|
+
}
|
105
|
+
crfsuite_item_finish(&item);
|
106
|
+
break;
|
107
|
+
case IWA_ITEM:
|
108
|
+
if (lid == -1) {
|
109
|
+
lid = labels->get(labels, token->attr);
|
110
|
+
} else {
|
111
|
+
crfsuite_attribute_init(&cont);
|
112
|
+
cont.aid = attrs->get(attrs, token->attr);
|
113
|
+
if (token->value && *token->value) {
|
114
|
+
cont.value = atof(token->value);
|
115
|
+
} else {
|
116
|
+
cont.value = 1.0;
|
117
|
+
}
|
118
|
+
crfsuite_item_append_attribute(&item, &cont);
|
119
|
+
}
|
120
|
+
break;
|
121
|
+
case IWA_NONE:
|
122
|
+
case IWA_EOF:
|
123
|
+
/* Put the training instance. */
|
124
|
+
crfsuite_data_append(data, &inst);
|
125
|
+
crfsuite_instance_finish(&inst);
|
126
|
+
inst.group = group;
|
127
|
+
++n;
|
128
|
+
break;
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
progress(fpo, prev, 100);
|
133
|
+
fprintf(fpo, "\n");
|
134
|
+
|
135
|
+
return n;
|
136
|
+
}
|