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,1063 @@
|
|
1
|
+
/*
|
2
|
+
* CRFsuite library.
|
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 __CRFSUITE_H__
|
34
|
+
#define __CRFSUITE_H__
|
35
|
+
|
36
|
+
#ifdef __cplusplus
|
37
|
+
extern "C" {
|
38
|
+
#endif/*__cplusplus*/
|
39
|
+
|
40
|
+
#include <stdio.h>
|
41
|
+
#include <stdarg.h>
|
42
|
+
|
43
|
+
/**
|
44
|
+
* \addtogroup crfsuite_api CRFSuite C API
|
45
|
+
* @{
|
46
|
+
*
|
47
|
+
* The CRFSuite C API provides a low-level library for manupulating
|
48
|
+
* CRFSuite in C language.
|
49
|
+
*/
|
50
|
+
|
51
|
+
/**
|
52
|
+
* \addtogroup crfsuite_misc Miscellaneous definitions and functions
|
53
|
+
* @{
|
54
|
+
*/
|
55
|
+
|
56
|
+
/** Version number of CRFSuite library. */
|
57
|
+
#define CRFSUITE_VERSION "0.12"
|
58
|
+
|
59
|
+
/** Copyright string of CRFSuite library. */
|
60
|
+
#define CRFSUITE_COPYRIGHT "Copyright (c) 2007-2011 Naoaki Okazaki"
|
61
|
+
|
62
|
+
/** Type of a float value. */
|
63
|
+
typedef double floatval_t;
|
64
|
+
|
65
|
+
/** Maximum value of a float value. */
|
66
|
+
#define FLOAT_MAX DBL_MAX
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Status codes.
|
70
|
+
*/
|
71
|
+
enum {
|
72
|
+
/** Success. */
|
73
|
+
CRFSUITE_SUCCESS = 0,
|
74
|
+
/** Unknown error occurred. */
|
75
|
+
CRFSUITEERR_UNKNOWN = 0x80000000,
|
76
|
+
/** Insufficient memory. */
|
77
|
+
CRFSUITEERR_OUTOFMEMORY,
|
78
|
+
/** Unsupported operation. */
|
79
|
+
CRFSUITEERR_NOTSUPPORTED,
|
80
|
+
/** Incompatible data. */
|
81
|
+
CRFSUITEERR_INCOMPATIBLE,
|
82
|
+
/** Internal error. */
|
83
|
+
CRFSUITEERR_INTERNAL_LOGIC,
|
84
|
+
/** Overflow. */
|
85
|
+
CRFSUITEERR_OVERFLOW,
|
86
|
+
/** Not implemented. */
|
87
|
+
CRFSUITEERR_NOTIMPLEMENTED,
|
88
|
+
};
|
89
|
+
|
90
|
+
/**@}*/
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
/**
|
95
|
+
* \addtogroup crfsuite_object Object interfaces and utilities.
|
96
|
+
* @{
|
97
|
+
*/
|
98
|
+
|
99
|
+
struct tag_crfsuite_model;
|
100
|
+
/** CRFSuite model interface. */
|
101
|
+
typedef struct tag_crfsuite_model crfsuite_model_t;
|
102
|
+
|
103
|
+
struct tag_crfsuite_trainer;
|
104
|
+
/** CRFSuite trainer interface. */
|
105
|
+
typedef struct tag_crfsuite_trainer crfsuite_trainer_t;
|
106
|
+
|
107
|
+
struct tag_crfsuite_tagger;
|
108
|
+
/** CRFSuite tagger interface. */
|
109
|
+
typedef struct tag_crfsuite_tagger crfsuite_tagger_t;
|
110
|
+
|
111
|
+
struct tag_crfsuite_dictionary;
|
112
|
+
/** CRFSuite dictionary interface. */
|
113
|
+
typedef struct tag_crfsuite_dictionary crfsuite_dictionary_t;
|
114
|
+
|
115
|
+
struct tag_crfsuite_params;
|
116
|
+
/** CRFSuite parameter interface. */
|
117
|
+
typedef struct tag_crfsuite_params crfsuite_params_t;
|
118
|
+
|
119
|
+
/**@}*/
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
/**
|
124
|
+
* \addtogroup crfsuite_data Dataset (attribute, item, instance, dataset)
|
125
|
+
* @{
|
126
|
+
*/
|
127
|
+
|
128
|
+
/**
|
129
|
+
* An attribute.
|
130
|
+
* An attribute consists of an attribute id with its value.
|
131
|
+
*/
|
132
|
+
typedef struct {
|
133
|
+
int aid; /**< Attribute id. */
|
134
|
+
floatval_t value; /**< Value of the attribute. */
|
135
|
+
} crfsuite_attribute_t;
|
136
|
+
|
137
|
+
/**
|
138
|
+
* An item.
|
139
|
+
* An item consists of an array of attributes.
|
140
|
+
*/
|
141
|
+
typedef struct {
|
142
|
+
/** Number of contents associated with the item. */
|
143
|
+
int num_contents;
|
144
|
+
/** Maximum number of contents (internal use). */
|
145
|
+
int cap_contents;
|
146
|
+
/** Array of the attributes. */
|
147
|
+
crfsuite_attribute_t *contents;
|
148
|
+
} crfsuite_item_t;
|
149
|
+
|
150
|
+
/**
|
151
|
+
* An instance (sequence of items and labels).
|
152
|
+
* An instance consists of a sequence of items and labels.
|
153
|
+
*/
|
154
|
+
typedef struct {
|
155
|
+
/** Number of items/labels in the sequence. */
|
156
|
+
int num_items;
|
157
|
+
/** Maximum number of items/labels (internal use). */
|
158
|
+
int cap_items;
|
159
|
+
/** Array of the item sequence. */
|
160
|
+
crfsuite_item_t *items;
|
161
|
+
/** Array of the label sequence. */
|
162
|
+
int *labels;
|
163
|
+
/** Group ID of the instance. */
|
164
|
+
int group;
|
165
|
+
} crfsuite_instance_t;
|
166
|
+
|
167
|
+
/**
|
168
|
+
* A data set.
|
169
|
+
* A data set consists of an array of instances and dictionary objects
|
170
|
+
* for attributes and labels.
|
171
|
+
*/
|
172
|
+
typedef struct {
|
173
|
+
/** Number of instances. */
|
174
|
+
int num_instances;
|
175
|
+
/** Maximum number of instances (internal use). */
|
176
|
+
int cap_instances;
|
177
|
+
/** Array of instances. */
|
178
|
+
crfsuite_instance_t* instances;
|
179
|
+
|
180
|
+
/** Dictionary object for attributes. */
|
181
|
+
crfsuite_dictionary_t *attrs;
|
182
|
+
/** Dictionary object for labels. */
|
183
|
+
crfsuite_dictionary_t *labels;
|
184
|
+
} crfsuite_data_t;
|
185
|
+
|
186
|
+
/**@}*/
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
/**
|
191
|
+
* \addtogroup crfsuite_evaluation Evaluation utility
|
192
|
+
* @{
|
193
|
+
*/
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Label-wise performance values.
|
197
|
+
*/
|
198
|
+
typedef struct {
|
199
|
+
/** Number of correct predictions. */
|
200
|
+
int num_correct;
|
201
|
+
/** Number of occurrences of the label in the gold-standard data. */
|
202
|
+
int num_observation;
|
203
|
+
/** Number of predictions. */
|
204
|
+
int num_model;
|
205
|
+
/** Precision. */
|
206
|
+
floatval_t precision;
|
207
|
+
/** Recall. */
|
208
|
+
floatval_t recall;
|
209
|
+
/** F1 score. */
|
210
|
+
floatval_t fmeasure;
|
211
|
+
} crfsuite_label_evaluation_t;
|
212
|
+
|
213
|
+
/**
|
214
|
+
* An overall performance values.
|
215
|
+
*/
|
216
|
+
typedef struct {
|
217
|
+
/** Number of labels. */
|
218
|
+
int num_labels;
|
219
|
+
/** Array of label-wise evaluations. */
|
220
|
+
crfsuite_label_evaluation_t* tbl;
|
221
|
+
|
222
|
+
/** Number of correctly predicted items. */
|
223
|
+
int item_total_correct;
|
224
|
+
/** Total number of items. */
|
225
|
+
int item_total_num;
|
226
|
+
/** Total number of occurrences of labels in the gold-standard data. */
|
227
|
+
int item_total_observation;
|
228
|
+
/** Total number of predictions. */
|
229
|
+
int item_total_model;
|
230
|
+
/** Item-level accuracy. */
|
231
|
+
floatval_t item_accuracy;
|
232
|
+
|
233
|
+
/** Number of correctly predicted instances. */
|
234
|
+
int inst_total_correct;
|
235
|
+
/** Total number of instances. */
|
236
|
+
int inst_total_num;
|
237
|
+
/** Instance-level accuracy. */
|
238
|
+
floatval_t inst_accuracy;
|
239
|
+
|
240
|
+
/** Macro-averaged precision. */
|
241
|
+
floatval_t macro_precision;
|
242
|
+
/** Macro-averaged recall. */
|
243
|
+
floatval_t macro_recall;
|
244
|
+
/** Macro-averaged F1 score. */
|
245
|
+
floatval_t macro_fmeasure;
|
246
|
+
} crfsuite_evaluation_t;
|
247
|
+
|
248
|
+
/**@}*/
|
249
|
+
|
250
|
+
|
251
|
+
/**
|
252
|
+
* \addtogroup crfsuite_object
|
253
|
+
* @{
|
254
|
+
*/
|
255
|
+
|
256
|
+
/**
|
257
|
+
* Type of callback function for logging.
|
258
|
+
* @param user Pointer to the user-defined data.
|
259
|
+
* @param format Format string (compatible with prinf()).
|
260
|
+
* @param args Optional arguments for the format string.
|
261
|
+
* @return int \c 0 to continue; non-zero to cancel the training.
|
262
|
+
*/
|
263
|
+
typedef int (*crfsuite_logging_callback)(void *user, const char *format, va_list args);
|
264
|
+
|
265
|
+
|
266
|
+
/**
|
267
|
+
* CRFSuite model interface.
|
268
|
+
*/
|
269
|
+
struct tag_crfsuite_model {
|
270
|
+
/**
|
271
|
+
* Pointer to the internal data (internal use only).
|
272
|
+
*/
|
273
|
+
void *internal;
|
274
|
+
|
275
|
+
/**
|
276
|
+
* Reference counter (internal use only).
|
277
|
+
*/
|
278
|
+
int nref;
|
279
|
+
|
280
|
+
/**
|
281
|
+
* Increment the reference counter.
|
282
|
+
* @param model The pointer to this model instance.
|
283
|
+
* @return int The reference count after this increment.
|
284
|
+
*/
|
285
|
+
int (*addref)(crfsuite_model_t* model);
|
286
|
+
|
287
|
+
/**
|
288
|
+
* Decrement the reference counter.
|
289
|
+
* @param model The pointer to this model instance.
|
290
|
+
* @return int The reference count after this operation.
|
291
|
+
*/
|
292
|
+
int (*release)(crfsuite_model_t* model);
|
293
|
+
|
294
|
+
/**
|
295
|
+
* Obtain the pointer to crfsuite_tagger_t interface.
|
296
|
+
* @param model The pointer to this model instance.
|
297
|
+
* @param ptr_tagger The pointer that receives a crfsuite_tagger_t
|
298
|
+
* pointer.
|
299
|
+
* @return int The status code.
|
300
|
+
*/
|
301
|
+
int (*get_tagger)(crfsuite_model_t* model, crfsuite_tagger_t** ptr_tagger);
|
302
|
+
|
303
|
+
/**
|
304
|
+
* Obtain the pointer to crfsuite_dictionary_t interface for labels.
|
305
|
+
* @param model The pointer to this model instance.
|
306
|
+
* @param ptr_labels The pointer that receives a crfsuite_dictionary_t
|
307
|
+
* pointer.
|
308
|
+
* @return int The status code.
|
309
|
+
*/
|
310
|
+
int (*get_labels)(crfsuite_model_t* model, crfsuite_dictionary_t** ptr_labels);
|
311
|
+
|
312
|
+
/**
|
313
|
+
* Obtain the pointer to crfsuite_dictionary_t interface for attributes.
|
314
|
+
* @param model The pointer to this model instance.
|
315
|
+
* @param ptr_attrs The pointer that receives a crfsuite_dictionary_t
|
316
|
+
* pointer.
|
317
|
+
* @return int The status code.
|
318
|
+
*/
|
319
|
+
int (*get_attrs)(crfsuite_model_t* model, crfsuite_dictionary_t** ptr_attrs);
|
320
|
+
|
321
|
+
/**
|
322
|
+
* Print the model in human-readable format.
|
323
|
+
* @param model The pointer to this model instance.
|
324
|
+
* @param fpo The FILE* pointer.
|
325
|
+
* @param ptr_attrs The pointer that receives a crfsuite_dictionary_t
|
326
|
+
* pointer.
|
327
|
+
* @return int The status code.
|
328
|
+
*/
|
329
|
+
int (*dump)(crfsuite_model_t* model, FILE *fpo);
|
330
|
+
};
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
/**
|
335
|
+
* CRFSuite trainer interface.
|
336
|
+
*/
|
337
|
+
struct tag_crfsuite_trainer {
|
338
|
+
/**
|
339
|
+
* Pointer to the internal data (internal use only).
|
340
|
+
*/
|
341
|
+
void *internal;
|
342
|
+
|
343
|
+
/**
|
344
|
+
* Reference counter (internal use only).
|
345
|
+
*/
|
346
|
+
int nref;
|
347
|
+
|
348
|
+
/**
|
349
|
+
* Increment the reference counter.
|
350
|
+
* @param trainer The pointer to this trainer instance.
|
351
|
+
* @return int The reference count after this increment.
|
352
|
+
*/
|
353
|
+
int (*addref)(crfsuite_trainer_t* trainer);
|
354
|
+
|
355
|
+
/**
|
356
|
+
* Decrement the reference counter.
|
357
|
+
* @param trainer The pointer to this trainer instance.
|
358
|
+
* @return int The reference count after this operation.
|
359
|
+
*/
|
360
|
+
int (*release)(crfsuite_trainer_t* trainer);
|
361
|
+
|
362
|
+
/**
|
363
|
+
* Obtain the pointer to crfsuite_params_t interface.
|
364
|
+
* @param trainer The pointer to this trainer instance.
|
365
|
+
* @return crfsuite_params_t* The pointer to crfsuite_params_t.
|
366
|
+
*/
|
367
|
+
crfsuite_params_t* (*params)(crfsuite_trainer_t* trainer);
|
368
|
+
|
369
|
+
/**
|
370
|
+
* Set the callback function and user-defined data.
|
371
|
+
* @param trainer The pointer to this trainer instance.
|
372
|
+
* @param user The pointer to the user-defined data.
|
373
|
+
* @param cbm The pointer to the callback function.
|
374
|
+
*/
|
375
|
+
void (*set_message_callback)(crfsuite_trainer_t* trainer, void *user, crfsuite_logging_callback cbm);
|
376
|
+
|
377
|
+
/**
|
378
|
+
* Start a training process.
|
379
|
+
* @param trainer The pointer to this trainer instance.
|
380
|
+
* @param data The poiinter to the data set.
|
381
|
+
* @param filename The filename to which the trainer stores the model.
|
382
|
+
* If an empty string is specified, this function
|
383
|
+
* does not sture the model to a file.
|
384
|
+
* @param holdout The holdout group.
|
385
|
+
* @return int The status code.
|
386
|
+
*/
|
387
|
+
int (*train)(crfsuite_trainer_t* trainer, const crfsuite_data_t *data, const char *filename, int holdout);
|
388
|
+
};
|
389
|
+
|
390
|
+
/**
|
391
|
+
* CRFSuite tagger interface.
|
392
|
+
*/
|
393
|
+
struct tag_crfsuite_tagger {
|
394
|
+
/**
|
395
|
+
* Pointer to the internal data (internal use only).
|
396
|
+
*/
|
397
|
+
void *internal;
|
398
|
+
|
399
|
+
/**
|
400
|
+
* Reference counter (internal use only).
|
401
|
+
*/
|
402
|
+
int nref;
|
403
|
+
|
404
|
+
/**
|
405
|
+
* Increment the reference counter.
|
406
|
+
* @param tagger The pointer to this tagger instance.
|
407
|
+
* @return int The reference count after this increment.
|
408
|
+
*/
|
409
|
+
int (*addref)(crfsuite_tagger_t* tagger);
|
410
|
+
|
411
|
+
/**
|
412
|
+
* Decrement the reference counter.
|
413
|
+
* @param tagger The pointer to this tagger instance.
|
414
|
+
* @return int The reference count after this operation.
|
415
|
+
*/
|
416
|
+
int (*release)(crfsuite_tagger_t* tagger);
|
417
|
+
|
418
|
+
/**
|
419
|
+
* Set an instance to the tagger.
|
420
|
+
* @param tagger The pointer to this tagger instance.
|
421
|
+
* @param inst The item sequence to be tagged.
|
422
|
+
* @return int The status code.
|
423
|
+
*/
|
424
|
+
int (*set)(crfsuite_tagger_t* tagger, crfsuite_instance_t *inst);
|
425
|
+
|
426
|
+
/**
|
427
|
+
* Obtain the number of items in the current instance.
|
428
|
+
* @param tagger The pointer to this tagger instance.
|
429
|
+
* @return int The number of items of the instance set by
|
430
|
+
* set() function.
|
431
|
+
* @return int The status code.
|
432
|
+
*/
|
433
|
+
int (*length)(crfsuite_tagger_t* tagger);
|
434
|
+
|
435
|
+
/**
|
436
|
+
* Find the Viterbi label sequence.
|
437
|
+
* @param tagger The pointer to this tagger instance.
|
438
|
+
* @param labels The label array that receives the Viterbi label
|
439
|
+
* sequence. The number of elements in the array must
|
440
|
+
* be no smaller than the number of item.
|
441
|
+
* @param ptr_score The pointer to a float variable that receives the
|
442
|
+
* score of the Viterbi label sequence.
|
443
|
+
* @return int The status code.
|
444
|
+
*/
|
445
|
+
int (*viterbi)(crfsuite_tagger_t* tagger, int *labels, floatval_t *ptr_score);
|
446
|
+
|
447
|
+
/**
|
448
|
+
* Compute the score of a label sequence.
|
449
|
+
* @param tagger The pointer to this tagger instance.
|
450
|
+
* @param path The label sequence.
|
451
|
+
* @param ptr_score The pointer to a float variable that receives the
|
452
|
+
* score of the label sequence.
|
453
|
+
* @return int The status code.
|
454
|
+
*/
|
455
|
+
int (*score)(crfsuite_tagger_t* tagger, int *path, floatval_t *ptr_score);
|
456
|
+
|
457
|
+
/**
|
458
|
+
* Compute the log of the partition factor (normalization constant).
|
459
|
+
* @param tagger The pointer to this tagger instance.
|
460
|
+
* @param ptr_score The pointer to a float variable that receives the
|
461
|
+
* logarithm of the partition factor.
|
462
|
+
* @return int The status code.
|
463
|
+
*/
|
464
|
+
int (*lognorm)(crfsuite_tagger_t* tagger, floatval_t *ptr_norm);
|
465
|
+
|
466
|
+
/**
|
467
|
+
* Compute the marginal probability of a label at a position.
|
468
|
+
* This function computes P(y_t = l | x), the probability when
|
469
|
+
* y_t is the label (l).
|
470
|
+
* @param tagger The pointer to this tagger instance.
|
471
|
+
* @param l The label.
|
472
|
+
* @param t The position.
|
473
|
+
* @param ptr_prob The pointer to a float variable that receives the
|
474
|
+
* marginal probability.
|
475
|
+
* @return int The status code.
|
476
|
+
*/
|
477
|
+
int (*marginal_point)(crfsuite_tagger_t *tagger, int l, int t, floatval_t *ptr_prob);
|
478
|
+
|
479
|
+
/**
|
480
|
+
* Compute the marginal probability of a partial label sequence.
|
481
|
+
* @param tagger The pointer to this tagger instance.
|
482
|
+
* @param path The partial label sequence.
|
483
|
+
* @param begin The start position of the partial label sequence.
|
484
|
+
* @param end The last+1 position of the partial label sequence.
|
485
|
+
* @param ptr_prob The pointer to a float variable that receives the
|
486
|
+
* marginal probability.
|
487
|
+
* @return int The status code.
|
488
|
+
*/
|
489
|
+
int (*marginal_path)(crfsuite_tagger_t *tagger, const int *path, int begin, int end, floatval_t *ptr_prob);
|
490
|
+
};
|
491
|
+
|
492
|
+
/**
|
493
|
+
* CRFSuite dictionary interface.
|
494
|
+
*/
|
495
|
+
struct tag_crfsuite_dictionary {
|
496
|
+
/**
|
497
|
+
* Pointer to the internal data (internal use only).
|
498
|
+
*/
|
499
|
+
void *internal;
|
500
|
+
|
501
|
+
/**
|
502
|
+
* Reference counter (internal use only).
|
503
|
+
*/
|
504
|
+
int nref;
|
505
|
+
|
506
|
+
/**
|
507
|
+
* Increment the reference counter.
|
508
|
+
* @param dic The pointer to this dictionary instance.
|
509
|
+
* @return int The reference count after this increment.
|
510
|
+
*/
|
511
|
+
int (*addref)(crfsuite_dictionary_t* dic);
|
512
|
+
|
513
|
+
/**
|
514
|
+
* Decrement the reference counter.
|
515
|
+
* @param dic The pointer to this dictionary instance.
|
516
|
+
* @return int The reference count after this operation.
|
517
|
+
*/
|
518
|
+
int (*release)(crfsuite_dictionary_t* dic);
|
519
|
+
|
520
|
+
/**
|
521
|
+
* Assign and obtain the integer ID for the string.
|
522
|
+
* @param dic The pointer to this dictionary instance.
|
523
|
+
* @param str The string.
|
524
|
+
* @return int The ID associated with the string if any,
|
525
|
+
* the new ID otherwise.
|
526
|
+
*/
|
527
|
+
int (*get)(crfsuite_dictionary_t* dic, const char *str);
|
528
|
+
|
529
|
+
/**
|
530
|
+
* Obtain the integer ID for the string.
|
531
|
+
* @param dic The pointer to this dictionary instance.
|
532
|
+
* @param str The string.
|
533
|
+
* @return int The ID associated with the string if any,
|
534
|
+
* \c -1 otherwise.
|
535
|
+
*/
|
536
|
+
int (*to_id)(crfsuite_dictionary_t* dic, const char *str);
|
537
|
+
|
538
|
+
/**
|
539
|
+
* Obtain the string for the ID.
|
540
|
+
* @param dic The pointer to this dictionary instance.
|
541
|
+
* @param id the string ID.
|
542
|
+
* @param pstr \c *pstr points to the string associated with
|
543
|
+
* the ID if any, \c NULL otherwise.
|
544
|
+
* @return int \c 0 if the string ID is associated with a string,
|
545
|
+
* \c 1 otherwise.
|
546
|
+
*/
|
547
|
+
int (*to_string)(crfsuite_dictionary_t* dic, int id, char const **pstr);
|
548
|
+
|
549
|
+
/**
|
550
|
+
* Obtain the number of strings in the dictionary.
|
551
|
+
* @param dic The pointer to this dictionary instance.
|
552
|
+
* @return int The number of strings stored in the dictionary.
|
553
|
+
*/
|
554
|
+
int (*num)(crfsuite_dictionary_t* dic);
|
555
|
+
|
556
|
+
/**
|
557
|
+
* Free the memory block allocated by to_string() function.
|
558
|
+
* @param dic The pointer to this dictionary instance.
|
559
|
+
* @param str The pointer to the string whose memory block is
|
560
|
+
* freed.
|
561
|
+
*/
|
562
|
+
void (*free)(crfsuite_dictionary_t* dic, const char *str);
|
563
|
+
};
|
564
|
+
|
565
|
+
/**
|
566
|
+
* CRFSuite parameter interface.
|
567
|
+
*/
|
568
|
+
struct tag_crfsuite_params {
|
569
|
+
/**
|
570
|
+
* Pointer to the instance data (internal use only).
|
571
|
+
*/
|
572
|
+
void *internal;
|
573
|
+
|
574
|
+
/**
|
575
|
+
* Reference counter (internal use only).
|
576
|
+
*/
|
577
|
+
int nref;
|
578
|
+
|
579
|
+
/**
|
580
|
+
* Increment the reference counter.
|
581
|
+
* @param params The pointer to this parameter instance.
|
582
|
+
* @return int The reference count after this increment.
|
583
|
+
*/
|
584
|
+
int (*addref)(crfsuite_params_t* params);
|
585
|
+
|
586
|
+
/**
|
587
|
+
* Decrement the reference counter.
|
588
|
+
* @param params The pointer to this parameter instance.
|
589
|
+
* @return int The reference count after this operation.
|
590
|
+
*/
|
591
|
+
int (*release)(crfsuite_params_t* params);
|
592
|
+
|
593
|
+
/**
|
594
|
+
* Obtain the number of available parameters.
|
595
|
+
* @param params The pointer to this parameter instance.
|
596
|
+
* @return int The number of parameters maintained by this object.
|
597
|
+
*/
|
598
|
+
int (*num)(crfsuite_params_t* params);
|
599
|
+
|
600
|
+
/**
|
601
|
+
* Obtain the name of a parameter.
|
602
|
+
* @param params The pointer to this parameter instance.
|
603
|
+
* @param i The parameter index.
|
604
|
+
* @param ptr_name *ptr_name points to the parameter name.
|
605
|
+
* @return int \c 0 always.
|
606
|
+
*/
|
607
|
+
int (*name)(crfsuite_params_t* params, int i, char **ptr_name);
|
608
|
+
|
609
|
+
/**
|
610
|
+
* Set a parameter value.
|
611
|
+
* @param params The pointer to this parameter instance.
|
612
|
+
* @param name The parameter name.
|
613
|
+
* @param value The parameter value in string format.
|
614
|
+
* @return int \c 0 if the parameter is found, \c -1 otherwise.
|
615
|
+
*/
|
616
|
+
int (*set)(crfsuite_params_t* params, const char *name, const char *value);
|
617
|
+
|
618
|
+
/**
|
619
|
+
* Get a parameter value.
|
620
|
+
* @param params The pointer to this parameter instance.
|
621
|
+
* @param name The parameter name.
|
622
|
+
* @param ptr_value *ptr_value presents the parameter value in string
|
623
|
+
* format.
|
624
|
+
* @return int \c 0 if the parameter is found, \c -1 otherwise.
|
625
|
+
*/
|
626
|
+
int (*get)(crfsuite_params_t* params, const char *name, char **ptr_value);
|
627
|
+
|
628
|
+
/**
|
629
|
+
* Set an integer value of a parameter.
|
630
|
+
* @param params The pointer to this parameter instance.
|
631
|
+
* @param name The parameter name.
|
632
|
+
* @param value The parameter value.
|
633
|
+
* @return int \c 0 if the parameter value is set successfully,
|
634
|
+
* \c -1 otherwise (unknown parameter or incompatible
|
635
|
+
* type).
|
636
|
+
*/
|
637
|
+
int (*set_int)(crfsuite_params_t* params, const char *name, int value);
|
638
|
+
|
639
|
+
/**
|
640
|
+
* Set a float value of a parameter.
|
641
|
+
* @param params The pointer to this parameter instance.
|
642
|
+
* @param name The parameter name.
|
643
|
+
* @param value The parameter value.
|
644
|
+
* @return int \c 0 if the parameter value is set successfully,
|
645
|
+
* \c -1 otherwise (unknown parameter or incompatible
|
646
|
+
* type).
|
647
|
+
*/
|
648
|
+
int (*set_float)(crfsuite_params_t* params, const char *name, floatval_t value);
|
649
|
+
|
650
|
+
/**
|
651
|
+
* Set a string value of a parameter.
|
652
|
+
* @param params The pointer to this parameter instance.
|
653
|
+
* @param name The parameter name.
|
654
|
+
* @param value The parameter value.
|
655
|
+
* @return int \c 0 if the parameter value is set successfully,
|
656
|
+
* \c -1 otherwise (unknown parameter or incompatible
|
657
|
+
* type).
|
658
|
+
*/
|
659
|
+
int (*set_string)(crfsuite_params_t* params, const char *name, const char *value);
|
660
|
+
|
661
|
+
/**
|
662
|
+
* Get an integer value of a parameter.
|
663
|
+
* @param params The pointer to this parameter instance.
|
664
|
+
* @param name The parameter name.
|
665
|
+
* @param ptr_value The pointer to a variable that receives the
|
666
|
+
* integer value.
|
667
|
+
* @return int \c 0 if the parameter value is obtained
|
668
|
+
* successfully, \c -1 otherwise (unknown parameter
|
669
|
+
* or incompatible type).
|
670
|
+
*/
|
671
|
+
int (*get_int)(crfsuite_params_t* params, const char *name, int *ptr_value);
|
672
|
+
|
673
|
+
/**
|
674
|
+
* Get a float value of a parameter.
|
675
|
+
* @param params The pointer to this parameter instance.
|
676
|
+
* @param name The parameter name.
|
677
|
+
* @param ptr_value The pointer to a variable that receives the
|
678
|
+
* float value.
|
679
|
+
* @return int \c 0 if the parameter value is obtained
|
680
|
+
* successfully, \c -1 otherwise (unknown parameter
|
681
|
+
* or incompatible type).
|
682
|
+
*/
|
683
|
+
int (*get_float)(crfsuite_params_t* params, const char *name, floatval_t *ptr_value);
|
684
|
+
|
685
|
+
/**
|
686
|
+
* Get a string value of a parameter.
|
687
|
+
* @param params The pointer to this parameter instance.
|
688
|
+
* @param name The parameter name.
|
689
|
+
* @param ptr_value *ptr_value presents the parameter value.
|
690
|
+
* @return int \c 0 if the parameter value is obtained
|
691
|
+
* successfully, \c -1 otherwise (unknown parameter
|
692
|
+
* or incompatible type).
|
693
|
+
*/
|
694
|
+
int (*get_string)(crfsuite_params_t* params, const char *name, char **ptr_value);
|
695
|
+
|
696
|
+
/**
|
697
|
+
* Get the help message of a parameter.
|
698
|
+
* @param params The pointer to this parameter instance.
|
699
|
+
* @param name The parameter name.
|
700
|
+
* @param ptr_type The pointer to \c char* to which this function
|
701
|
+
* store the type of the parameter.
|
702
|
+
* @param ptr_help The pointer to \c char* to which this function
|
703
|
+
* store the help message of the parameter.
|
704
|
+
* @return int \c 0 if the parameter is found, \c -1 otherwise.
|
705
|
+
*/
|
706
|
+
int (*help)(crfsuite_params_t* params, const char *name, char **ptr_type, char **ptr_help);
|
707
|
+
|
708
|
+
/**
|
709
|
+
* Free the memory block of a string allocated by this object.
|
710
|
+
* @param params The pointer to this parameter instance.
|
711
|
+
* @param str The pointer to the string.
|
712
|
+
*/
|
713
|
+
void (*free)(crfsuite_params_t* params, const char *str);
|
714
|
+
};
|
715
|
+
|
716
|
+
/**@}*/
|
717
|
+
|
718
|
+
|
719
|
+
|
720
|
+
/**
|
721
|
+
* \addtogroup crfsuite_object
|
722
|
+
* @{
|
723
|
+
*/
|
724
|
+
|
725
|
+
/**
|
726
|
+
* Create an instance of an object by an interface identifier.
|
727
|
+
* @param iid The interface identifier.
|
728
|
+
* @param ptr The pointer to \c void* that points to the
|
729
|
+
* instance of the object if successful,
|
730
|
+
* *ptr points to \c NULL otherwise.
|
731
|
+
* @return int \c 0 if this function creates an object successfully,
|
732
|
+
* \c 1 otherwise.
|
733
|
+
*/
|
734
|
+
int crfsuite_create_instance(const char *iid, void **ptr);
|
735
|
+
|
736
|
+
/**
|
737
|
+
* Create an instance of a model object from a model file.
|
738
|
+
* @param filename The filename of the model.
|
739
|
+
* @param ptr The pointer to \c void* that points to the
|
740
|
+
* instance of the model object if successful,
|
741
|
+
* *ptr points to \c NULL otherwise.
|
742
|
+
* @return int \c 0 if this function creates an object successfully,
|
743
|
+
* \c 1 otherwise.
|
744
|
+
*/
|
745
|
+
int crfsuite_create_instance_from_file(const char *filename, void **ptr);
|
746
|
+
|
747
|
+
/**
|
748
|
+
* Create instances of tagging object from a model file.
|
749
|
+
* @param filename The filename of the model.
|
750
|
+
* @param ptr_tagger The pointer to \c void* that points to the
|
751
|
+
* instance of the tagger object if successful,
|
752
|
+
* *ptr points to \c NULL otherwise.
|
753
|
+
* @param ptr_attrs The pointer to \c void* that points to the
|
754
|
+
* instance of the dictionary object for attributes
|
755
|
+
* if successful, *ptr points to \c NULL otherwise.
|
756
|
+
* @param ptr_labels The pointer to \c void* that points to the
|
757
|
+
* instance of the dictionary object for labels
|
758
|
+
* if successful, *ptr points to \c NULL otherwise.
|
759
|
+
* @return int \c 0 if this function creates an object successfully,
|
760
|
+
* \c 1 otherwise.
|
761
|
+
*/
|
762
|
+
int crfsuite_create_tagger(
|
763
|
+
const char *filename,
|
764
|
+
crfsuite_tagger_t** ptr_tagger,
|
765
|
+
crfsuite_dictionary_t** ptr_attrs,
|
766
|
+
crfsuite_dictionary_t** ptr_labels
|
767
|
+
);
|
768
|
+
|
769
|
+
/**@}*/
|
770
|
+
|
771
|
+
|
772
|
+
|
773
|
+
/**
|
774
|
+
* \addtogroup crfsuite_data
|
775
|
+
* @{
|
776
|
+
*/
|
777
|
+
|
778
|
+
/**
|
779
|
+
* Initialize an attribute structure.
|
780
|
+
* @param attr The pointer to crfsuite_attribute_t.
|
781
|
+
*/
|
782
|
+
void crfsuite_attribute_init(crfsuite_attribute_t* attr);
|
783
|
+
|
784
|
+
/**
|
785
|
+
* Set an attribute and its value.
|
786
|
+
* @param attr The pointer to crfsuite_attribute_t.
|
787
|
+
* @param aid The attribute identifier.
|
788
|
+
* @param value The attribute value.
|
789
|
+
*/
|
790
|
+
void crfsuite_attribute_set(crfsuite_attribute_t* attr, int aid, floatval_t value);
|
791
|
+
|
792
|
+
/**
|
793
|
+
* Copy the content of an attribute structure.
|
794
|
+
* @param dst The pointer to the destination.
|
795
|
+
* @param src The pointer to the source.
|
796
|
+
*/
|
797
|
+
void crfsuite_attribute_copy(crfsuite_attribute_t* dst, const crfsuite_attribute_t* src);
|
798
|
+
|
799
|
+
/**
|
800
|
+
* Swap the contents of two attribute structures.
|
801
|
+
* @param x The pointer to an attribute structure.
|
802
|
+
* @param y The pointer to another attribute structure.
|
803
|
+
*/
|
804
|
+
void crfsuite_attribute_swap(crfsuite_attribute_t* x, crfsuite_attribute_t* y);
|
805
|
+
|
806
|
+
/**
|
807
|
+
* Initialize an item structure.
|
808
|
+
* @param item The pointer to crfsuite_item_t.
|
809
|
+
*/
|
810
|
+
void crfsuite_item_init(crfsuite_item_t* item);
|
811
|
+
|
812
|
+
/**
|
813
|
+
* Initialize an item structure with the number of attributes.
|
814
|
+
* @param item The pointer to crfsuite_item_t.
|
815
|
+
* @param num_attributes The number of attributes.
|
816
|
+
*/
|
817
|
+
void crfsuite_item_init_n(crfsuite_item_t* item, int num_attributes);
|
818
|
+
|
819
|
+
/**
|
820
|
+
* Uninitialize an item structure.
|
821
|
+
* @param item The pointer to crfsuite_item_t.
|
822
|
+
*/
|
823
|
+
void crfsuite_item_finish(crfsuite_item_t* item);
|
824
|
+
|
825
|
+
/**
|
826
|
+
* Copy the content of an item structure.
|
827
|
+
* @param dst The pointer to the destination.
|
828
|
+
* @param src The pointer to the source.
|
829
|
+
*/
|
830
|
+
void crfsuite_item_copy(crfsuite_item_t* dst, const crfsuite_item_t* src);
|
831
|
+
|
832
|
+
/**
|
833
|
+
* Swap the contents of two item structures.
|
834
|
+
* @param x The pointer to an item structure.
|
835
|
+
* @param y The pointer to another item structure.
|
836
|
+
*/
|
837
|
+
void crfsuite_item_swap(crfsuite_item_t* x, crfsuite_item_t* y);
|
838
|
+
|
839
|
+
/**
|
840
|
+
* Append an attribute to the item structure.
|
841
|
+
* @param item The pointer to crfsuite_item_t.
|
842
|
+
* @param attr The attribute to be added to the item.
|
843
|
+
* @return int \c 0 if successful, \c -1 otherwise.
|
844
|
+
*/
|
845
|
+
int crfsuite_item_append_attribute(crfsuite_item_t* item, const crfsuite_attribute_t* attr);
|
846
|
+
|
847
|
+
/**
|
848
|
+
* Check whether the item has no attribute.
|
849
|
+
* @param item The pointer to crfsuite_item_t.
|
850
|
+
* @return int \c 1 if the item has no attribute, \c 0 otherwise.
|
851
|
+
*/
|
852
|
+
int crfsuite_item_empty(crfsuite_item_t* item);
|
853
|
+
|
854
|
+
|
855
|
+
|
856
|
+
/**
|
857
|
+
* Initialize an instance structure.
|
858
|
+
* @param seq The pointer to crfsuite_instance_t.
|
859
|
+
*/
|
860
|
+
void crfsuite_instance_init(crfsuite_instance_t* seq);
|
861
|
+
|
862
|
+
/**
|
863
|
+
* Initialize an instance structure with the number of items.
|
864
|
+
* @param seq The pointer to crfsuite_instance_t.
|
865
|
+
* @param num_items The number of items.
|
866
|
+
*/
|
867
|
+
void crfsuite_instance_init_n(crfsuite_instance_t* seq, int num_items);
|
868
|
+
|
869
|
+
/**
|
870
|
+
* Uninitialize an instance structure.
|
871
|
+
* @param seq The pointer to crfsuite_instance_t.
|
872
|
+
*/
|
873
|
+
void crfsuite_instance_finish(crfsuite_instance_t* seq);
|
874
|
+
|
875
|
+
/**
|
876
|
+
* Copy the content of an instance structure.
|
877
|
+
* @param dst The pointer to the destination.
|
878
|
+
* @param src The pointer to the source.
|
879
|
+
*/
|
880
|
+
void crfsuite_instance_copy(crfsuite_instance_t* dst, const crfsuite_instance_t* src);
|
881
|
+
|
882
|
+
/**
|
883
|
+
* Swap the contents of two instance structures.
|
884
|
+
* @param x The pointer to an instance structure.
|
885
|
+
* @param y The pointer to another instance structure.
|
886
|
+
*/
|
887
|
+
void crfsuite_instance_swap(crfsuite_instance_t* x, crfsuite_instance_t* y);
|
888
|
+
|
889
|
+
/**
|
890
|
+
* Append a pair of item and label to the instance structure.
|
891
|
+
* @param seq The pointer to crfsuite_instance_t.
|
892
|
+
* @param item The item to be added to the instance.
|
893
|
+
* @param label The label to be added to the instance.
|
894
|
+
* @return int \c 0 if successful, \c -1 otherwise.
|
895
|
+
*/
|
896
|
+
int crfsuite_instance_append(crfsuite_instance_t* seq, const crfsuite_item_t* item, int label);
|
897
|
+
|
898
|
+
/**
|
899
|
+
* Check whether the instance has no item.
|
900
|
+
* @param seq The pointer to crfsuite_instance_t.
|
901
|
+
* @return int \c 1 if the instance has no attribute, \c 0 otherwise.
|
902
|
+
*/
|
903
|
+
int crfsuite_instance_empty(crfsuite_instance_t* seq);
|
904
|
+
|
905
|
+
|
906
|
+
|
907
|
+
/**
|
908
|
+
* Initialize a dataset structure.
|
909
|
+
* @param data The pointer to crfsuite_data_t.
|
910
|
+
*/
|
911
|
+
void crfsuite_data_init(crfsuite_data_t* data);
|
912
|
+
|
913
|
+
/**
|
914
|
+
* Initialize a dataset structure with the number of instances.
|
915
|
+
* @param data The pointer to crfsuite_data_t.
|
916
|
+
* @param n The number of instances.
|
917
|
+
*/
|
918
|
+
void crfsuite_data_init_n(crfsuite_data_t* data, int n);
|
919
|
+
|
920
|
+
/**
|
921
|
+
* Uninitialize a dataset structure.
|
922
|
+
* @param data The pointer to crfsuite_data_t.
|
923
|
+
*/
|
924
|
+
void crfsuite_data_finish(crfsuite_data_t* data);
|
925
|
+
|
926
|
+
/**
|
927
|
+
* Copy the content of a dataset structure.
|
928
|
+
* @param dst The pointer to the destination.
|
929
|
+
* @param src The pointer to the source.
|
930
|
+
*/
|
931
|
+
void crfsuite_data_copy(crfsuite_data_t* dst, const crfsuite_data_t* src);
|
932
|
+
|
933
|
+
/**
|
934
|
+
* Swap the contents of two dataset structures.
|
935
|
+
* @param x The pointer to a dataset structure.
|
936
|
+
* @param y The pointer to another dataset structure.
|
937
|
+
*/
|
938
|
+
void crfsuite_data_swap(crfsuite_data_t* x, crfsuite_data_t* y);
|
939
|
+
|
940
|
+
/**
|
941
|
+
* Append an instance to the dataset structure.
|
942
|
+
* @param data The pointer to crfsuite_data_t.
|
943
|
+
* @param inst The instance to be added to the dataset.
|
944
|
+
* @return int \c 0 if successful, \c -1 otherwise.
|
945
|
+
*/
|
946
|
+
int crfsuite_data_append(crfsuite_data_t* data, const crfsuite_instance_t* inst);
|
947
|
+
|
948
|
+
/**
|
949
|
+
* Obtain the maximum length of the instances in the dataset.
|
950
|
+
* @param data The pointer to crfsuite_data_t.
|
951
|
+
* @return int The maximum number of items of the instances in the
|
952
|
+
* dataset.
|
953
|
+
*/
|
954
|
+
int crfsuite_data_maxlength(crfsuite_data_t* data);
|
955
|
+
|
956
|
+
/**
|
957
|
+
* Obtain the total number of items in the dataset.
|
958
|
+
* @param data The pointer to crfsuite_data_t.
|
959
|
+
* @return int The total number of items in the dataset.
|
960
|
+
*/
|
961
|
+
int crfsuite_data_totalitems(crfsuite_data_t* data);
|
962
|
+
|
963
|
+
/**@}*/
|
964
|
+
|
965
|
+
/**
|
966
|
+
* \addtogroup crfsuite_evaluation
|
967
|
+
*/
|
968
|
+
/**@{*/
|
969
|
+
|
970
|
+
/**
|
971
|
+
* Initialize an evaluation structure.
|
972
|
+
* @param eval The pointer to crfsuite_evaluation_t.
|
973
|
+
* @param n The number of labels in the dataset.
|
974
|
+
*/
|
975
|
+
void crfsuite_evaluation_init(crfsuite_evaluation_t* eval, int n);
|
976
|
+
|
977
|
+
/**
|
978
|
+
* Uninitialize an evaluation structure.
|
979
|
+
* @param eval The pointer to crfsuite_evaluation_t.
|
980
|
+
*/
|
981
|
+
void crfsuite_evaluation_finish(crfsuite_evaluation_t* eval);
|
982
|
+
|
983
|
+
/**
|
984
|
+
* Reset an evaluation structure.
|
985
|
+
* @param eval The pointer to crfsuite_evaluation_t.
|
986
|
+
*/
|
987
|
+
void crfsuite_evaluation_clear(crfsuite_evaluation_t* eval);
|
988
|
+
|
989
|
+
/**
|
990
|
+
* Accmulate the correctness of the predicted label sequence.
|
991
|
+
* @param eval The pointer to crfsuite_evaluation_t.
|
992
|
+
* @param reference The reference label sequence.
|
993
|
+
* @param prediction The predicted label sequence.
|
994
|
+
* @param T The length of the label sequence.
|
995
|
+
* @return int \c 0 if succeeded, \c 1 otherwise.
|
996
|
+
*/
|
997
|
+
int crfsuite_evaluation_accmulate(crfsuite_evaluation_t* eval, const int* reference, const int* prediction, int T);
|
998
|
+
|
999
|
+
/**
|
1000
|
+
* Finalize the evaluation result.
|
1001
|
+
* @param eval The pointer to crfsuite_evaluation_t.
|
1002
|
+
*/
|
1003
|
+
void crfsuite_evaluation_finalize(crfsuite_evaluation_t* eval);
|
1004
|
+
|
1005
|
+
/**
|
1006
|
+
* Print the evaluation result.
|
1007
|
+
* @param eval The pointer to crfsuite_evaluation_t.
|
1008
|
+
* @param labels The pointer to the label dictionary.
|
1009
|
+
* @param cbm The callback function to receive the evaluation result.
|
1010
|
+
* @param user The pointer to the user data that is forwarded to the
|
1011
|
+
* callback function.
|
1012
|
+
*/
|
1013
|
+
void crfsuite_evaluation_output(crfsuite_evaluation_t* eval, crfsuite_dictionary_t* labels, crfsuite_logging_callback cbm, void *user);
|
1014
|
+
|
1015
|
+
/**@}*/
|
1016
|
+
|
1017
|
+
|
1018
|
+
|
1019
|
+
/**
|
1020
|
+
* \addtogroup crfsuite_misc Miscellaneous definitions and functions
|
1021
|
+
* @{
|
1022
|
+
*/
|
1023
|
+
|
1024
|
+
/**
|
1025
|
+
* Increments the value of the integer variable as an atomic operation.
|
1026
|
+
* @param count The pointer to the integer variable.
|
1027
|
+
* @return The value after this increment.
|
1028
|
+
*/
|
1029
|
+
int crfsuite_interlocked_increment(int *count);
|
1030
|
+
|
1031
|
+
/**
|
1032
|
+
* Decrements the value of the integer variable as an atomic operation.
|
1033
|
+
* @param count The pointer to the integer variable.
|
1034
|
+
* @return The value after this decrement.
|
1035
|
+
*/
|
1036
|
+
int crfsuite_interlocked_decrement(int *count);
|
1037
|
+
|
1038
|
+
/**@}*/
|
1039
|
+
|
1040
|
+
/**@}*/
|
1041
|
+
|
1042
|
+
/**
|
1043
|
+
@mainpage CRFsuite: a fast implementation of Conditional Random Fields (CRFs)
|
1044
|
+
|
1045
|
+
@section intro Introduction
|
1046
|
+
|
1047
|
+
This document describes information for using
|
1048
|
+
<a href="http://www.chokkan.org/software/crfsuite">CRFsuite</a> from external
|
1049
|
+
programs. CRFsuite provides two APIs:
|
1050
|
+
- @link crfsuite_api C API @endlink: low-level and complete interface, which
|
1051
|
+
is used by the official frontend program.
|
1052
|
+
- @link crfsuite_hpp_api C++/SWIG API @endlink: high-level and easy-to-use
|
1053
|
+
interface for a number of programming languages (e.g, C++ and Python),
|
1054
|
+
which is a wrapper for the C API.
|
1055
|
+
|
1056
|
+
*/
|
1057
|
+
|
1058
|
+
|
1059
|
+
#ifdef __cplusplus
|
1060
|
+
}
|
1061
|
+
#endif/*__cplusplus*/
|
1062
|
+
|
1063
|
+
#endif/*__CRFSUITE_H__*/
|