├── NEWS ├── ChangeLog ├── stamp-h ├── stamp-h.in ├── README ├── stamp-h1 ├── AUTHORS ├── swig ├── version.h ├── version.h.in ├── Makefile └── CRFPP.i ├── default.css ├── doxygen ├── tab_b.gif ├── tab_l.gif ├── tab_r.gif ├── doxygen.png ├── tabs.css ├── index.html ├── namespaces.html ├── files.html ├── annotated.html ├── globals_type.html ├── namespacemembers_func.html ├── namespacemembers.html ├── classes.html ├── classCRFPP_1_1Model-members.html ├── globals_func.html ├── globals.html └── functions_func.html ├── example ├── JapaneseNE │ ├── test.data │ ├── train.data │ ├── exec.sh │ └── template ├── basenp │ ├── exec.sh │ └── template ├── seg │ ├── exec.sh │ └── template └── chunking │ ├── exec.sh │ └── template ├── COPYING ├── java ├── README ├── org │ └── chasen │ │ └── crfpp │ │ ├── CRFPP.java │ │ ├── CRFPPConstants.java │ │ ├── SWIGTYPE_p_int.java │ │ ├── SWIGTYPE_p_float.java │ │ ├── SWIGTYPE_p_p_char.java │ │ ├── Model.java │ │ ├── CRFPPJNI.java │ │ └── Tagger.java ├── Makefile ├── .am └── test.java ├── perl ├── README ├── Makefile.PL ├── test.pl └── CRFPP.pm ├── ruby ├── extconf.rb ├── README ├── test.rb └── Makefile ├── crf_test.cpp ├── crf_learn.cpp ├── python ├── setup.py ├── README ├── test.py └── CRFPP.py ├── make.bat ├── path.cpp ├── encoder.h ├── feature_cache.h ├── path.h ├── mkinstalldirs ├── feature_cache.cpp ├── Makefile.msvc ├── Makefile.msvc.in ├── node.cpp ├── stream_wrapper.h ├── BSD ├── timer.h ├── freelist.h ├── thread.h ├── node.h ├── sdk └── example.cpp ├── param.h ├── scoped_ptr.h ├── config.h.in ├── config.h ├── merge-models.pl ├── Makefile.am ├── autogen.sh ├── lbfgs.h ├── feature_index.h ├── feature.cpp ├── mmap.h ├── param.cpp ├── common.h ├── configure.in ├── tagger.h ├── INSTALL └── googlecode_upload.py /NEWS: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /stamp-h: -------------------------------------------------------------------------------- 1 | timestamp 2 | -------------------------------------------------------------------------------- /stamp-h.in: -------------------------------------------------------------------------------- 1 | timestamp 2 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | see doc/index.html 2 | 3 | -------------------------------------------------------------------------------- /stamp-h1: -------------------------------------------------------------------------------- 1 | timestamp for config.h 2 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Taku Kudo 2 | -------------------------------------------------------------------------------- /swig/version.h: -------------------------------------------------------------------------------- 1 | namespace CRFPP { 2 | #define VERSION "0.59" 3 | } 4 | -------------------------------------------------------------------------------- /default.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binhetech/crfpp/master/default.css -------------------------------------------------------------------------------- /swig/version.h.in: -------------------------------------------------------------------------------- 1 | namespace CRFPP { 2 | #define VERSION "@VERSION@" 3 | } 4 | -------------------------------------------------------------------------------- /doxygen/tab_b.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binhetech/crfpp/master/doxygen/tab_b.gif -------------------------------------------------------------------------------- /doxygen/tab_l.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binhetech/crfpp/master/doxygen/tab_l.gif -------------------------------------------------------------------------------- /doxygen/tab_r.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binhetech/crfpp/master/doxygen/tab_r.gif -------------------------------------------------------------------------------- /doxygen/doxygen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binhetech/crfpp/master/doxygen/doxygen.png -------------------------------------------------------------------------------- /example/JapaneseNE/test.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binhetech/crfpp/master/example/JapaneseNE/test.data -------------------------------------------------------------------------------- /example/JapaneseNE/train.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binhetech/crfpp/master/example/JapaneseNE/train.data -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | CRF++ is copyrighted free software by Taku Kudo , 2 | and is released under any of the LGPL (see the file LGPL) or the 3 | BSD License (see the file BSD). 4 | -------------------------------------------------------------------------------- /java/README: -------------------------------------------------------------------------------- 1 | CRF++ java module 2 | 3 | $Id: README,v 1.2 2005/12/25 16:55:43 taku-ku Exp $; 4 | 5 | See test.java as sample program. 6 | 7 | % java -classpath CRFPP.jar test -d ../dic 8 | -------------------------------------------------------------------------------- /perl/README: -------------------------------------------------------------------------------- 1 | CRF++ perl module 2 | 3 | 1. Installation 4 | 5 | % perl Makefile.PL 6 | % make 7 | % su 8 | # make install 9 | 10 | 2. How to use? 11 | 12 | See 'test.pl' as a sample program 13 | -------------------------------------------------------------------------------- /example/basenp/exec.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ../../crf_learn -c 10.0 template train.data model 3 | ../../crf_test -m model test.data 4 | 5 | ../../crf_learn -a MIRA template train.data model 6 | ../../crf_test -m model test.data 7 | rm -f model 8 | -------------------------------------------------------------------------------- /example/seg/exec.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ../../crf_learn -f 3 -c 4.0 template train.data model 3 | ../../crf_test -m model test.data 4 | 5 | ../../crf_learn -a MIRA -f 3 template train.data model 6 | ../../crf_test -m model test.data 7 | rm -f model 8 | -------------------------------------------------------------------------------- /example/JapaneseNE/exec.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ../../crf_learn -p2 -f 3 -c 4.0 template train.data model 3 | ../../crf_test -m model test.data 4 | 5 | ../../crf_learn -a MIRA -f 3 template train.data model 6 | ../../crf_test -m model test.data 7 | rm -f model 8 | -------------------------------------------------------------------------------- /ruby/extconf.rb: -------------------------------------------------------------------------------- 1 | require 'mkmf' 2 | 3 | crfpp_config = with_config('crfpp-config', 'crfpp-config') 4 | use_crfpp_config = enable_config('crfpp-config') 5 | have_library("crfpp") 6 | have_library("pthread") 7 | have_header('crfpp.h') && create_makefile('CRFPP') 8 | -------------------------------------------------------------------------------- /ruby/README: -------------------------------------------------------------------------------- 1 | CRF++ ruby module 2 | 3 | $Id: README,v 1.1.1.1 2005/12/03 14:18:52 taku-ku Exp $; 4 | 5 | 1. Installation 6 | 7 | % ruby extconf.rb 8 | % make 9 | % su 10 | # make install 11 | 12 | 2. How to use? 13 | 14 | See 'test.rb' as a sample program. 15 | -------------------------------------------------------------------------------- /example/seg/template: -------------------------------------------------------------------------------- 1 | # Unigram 2 | U00:%x[-2,0] 3 | U01:%x[-1,0] 4 | U02:%x[0,0] 5 | U03:%x[1,0] 6 | U04:%x[2,0] 7 | U05:%x[-2,0]/%x[-1,0]/%x[0,0] 8 | U06:%x[-1,0]/%x[0,0]/%x[1,0] 9 | U07:%x[0,0]/%x[1,0]/%x[2,0] 10 | U08:%x[-1,0]/%x[0,0] 11 | U09:%x[0,0]/%x[1,0] 12 | 13 | # Bigram 14 | B 15 | -------------------------------------------------------------------------------- /crf_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: crf_test.cpp 1587 2007-02-12 09:00:36Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #include "crfpp.h" 9 | #include "winmain.h" 10 | 11 | int main(int argc, char **argv) { 12 | return crfpp_test(argc, argv); 13 | } 14 | -------------------------------------------------------------------------------- /crf_learn.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: crf_learn.cpp 1587 2007-02-12 09:00:36Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #include "crfpp.h" 9 | #include "winmain.h" 10 | 11 | int main(int argc, char **argv) { 12 | return crfpp_learn(argc, argv); 13 | } 14 | -------------------------------------------------------------------------------- /perl/Makefile.PL: -------------------------------------------------------------------------------- 1 | use ExtUtils::MakeMaker; 2 | WriteMakefile( 3 | 'NAME' => 'CRFPP', 4 | 'CC' => 'c++', 5 | 'LD' => 'c++', 6 | 'INC' => '', 7 | 'LIBS' => '-lpthread -lcrfpp', 8 | # 'VERSION' => '0.46', 9 | 'OBJECT' => 'CRFPP_wrap.o' 10 | ); 11 | -------------------------------------------------------------------------------- /example/chunking/exec.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ../../crf_learn -c 4.0 template train.data model 3 | ../../crf_test -m model test.data 4 | 5 | ../../crf_learn -a MIRA template train.data model 6 | ../../crf_test -m model test.data 7 | 8 | #../../crf_learn -a CRF-L1 template train.data model 9 | #../../crf_test -m model test.data 10 | 11 | rm -f model 12 | -------------------------------------------------------------------------------- /python/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from distutils.core import setup,Extension,os 4 | import string 5 | 6 | setup(name = "mecab-python", 7 | py_modules=["CRFPP"], 8 | ext_modules = [Extension("_CRFPP", 9 | ["CRFPP_wrap.cxx",], 10 | libraries=["crfpp", "pthread"]) 11 | ]) 12 | -------------------------------------------------------------------------------- /make.bat: -------------------------------------------------------------------------------- 1 | Set PATH=c:\Program Files\Microsoft Visual Studio 8\VC\bin;%PATH% 2 | Set INCLUDE=c:\Program Files\Microsoft Visual Studio 8\VC\include;c:\Program Files\Microsoft Platform SDK\Include;%INCLUDE% 3 | Set LIB=c:\Program Files\Microsoft Visual Studio 8\VC\lib;c:\Program Files\Microsoft Platform SDK\Lib;%LIB% 4 | Set COMSPEC=cmd.exe 5 | nmake -f Makefile.msvc clean 6 | nmake -f Makefile.msvc 7 | 8 | 9 | -------------------------------------------------------------------------------- /python/README: -------------------------------------------------------------------------------- 1 | CRF++ python module 2 | 3 | $Id: README,v 1.1.1.1 2005/12/03 14:18:50 taku-ku Exp $; 4 | 5 | 1. Installation 6 | 7 | % python setup.py build 8 | % su 9 | # python setup.py install 10 | 11 | You can change the install directory with the --prefix option. For example: 12 | 13 | % python setup.py install --prefix=/tmp/pybuild/foobar 14 | 15 | 2. How to use? 16 | 17 | see 'test.py' as a sample program. 18 | -------------------------------------------------------------------------------- /example/chunking/template: -------------------------------------------------------------------------------- 1 | # Unigram 2 | U00:%x[-2,0] 3 | U01:%x[-1,0] 4 | U02:%x[0,0] 5 | U03:%x[1,0] 6 | U04:%x[2,0] 7 | U05:%x[-1,0]/%x[0,0] 8 | U06:%x[0,0]/%x[1,0] 9 | 10 | U10:%x[-2,1] 11 | U11:%x[-1,1] 12 | U12:%x[0,1] 13 | U13:%x[1,1] 14 | U14:%x[2,1] 15 | U15:%x[-2,1]/%x[-1,1] 16 | U16:%x[-1,1]/%x[0,1] 17 | U17:%x[0,1]/%x[1,1] 18 | U18:%x[1,1]/%x[2,1] 19 | 20 | U20:%x[-2,1]/%x[-1,1]/%x[0,1] 21 | U21:%x[-1,1]/%x[0,1]/%x[1,1] 22 | U22:%x[0,1]/%x[1,1]/%x[2,1] 23 | 24 | # Bigram 25 | B 26 | -------------------------------------------------------------------------------- /example/basenp/template: -------------------------------------------------------------------------------- 1 | # Unigram 2 | U00:%x[-2,0] 3 | U01:%x[-1,0] 4 | U02:%x[0,0] 5 | U03:%x[1,0] 6 | U04:%x[2,0] 7 | U05:%x[-1,0]/%x[0,0] 8 | U06:%x[0,0]/%x[1,0] 9 | 10 | U10:%x[-2,1] 11 | U11:%x[-1,1] 12 | U12:%x[0,1] 13 | U13:%x[1,1] 14 | U14:%x[2,1] 15 | U15:%x[-2,1]/%x[-1,1] 16 | U16:%x[-1,1]/%x[0,1] 17 | U17:%x[0,1]/%x[1,1] 18 | U18:%x[1,1]/%x[2,1] 19 | 20 | U20:%x[-2,1]/%x[-1,1]/%x[0,1] 21 | U21:%x[-1,1]/%x[0,1]/%x[1,1] 22 | U22:%x[0,1]/%x[1,1]/%x[2,1] 23 | 24 | U23:%x[0,1] 25 | 26 | # Bigram 27 | B 28 | -------------------------------------------------------------------------------- /java/org/chasen/crfpp/CRFPP.java: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 2.0.4 4 | * 5 | * Do not make changes to this file unless you know what you are doing--modify 6 | * the SWIG interface file instead. 7 | * ----------------------------------------------------------------------------- */ 8 | 9 | package org.chasen.crfpp; 10 | 11 | public class CRFPP implements CRFPPConstants { 12 | } 13 | -------------------------------------------------------------------------------- /java/org/chasen/crfpp/CRFPPConstants.java: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 2.0.4 4 | * 5 | * Do not make changes to this file unless you know what you are doing--modify 6 | * the SWIG interface file instead. 7 | * ----------------------------------------------------------------------------- */ 8 | 9 | package org.chasen.crfpp; 10 | 11 | public interface CRFPPConstants { 12 | public final static String VERSION = CRFPPJNI.VERSION_get(); 13 | } 14 | -------------------------------------------------------------------------------- /java/Makefile: -------------------------------------------------------------------------------- 1 | TARGET=CRFPP 2 | JAVAC=javac 3 | JAVA=java 4 | JAR=jar 5 | CXX=c++ 6 | INCLUDE=/usr/lib/jvm/java-7-openjdk-amd64/include 7 | 8 | PACKAGE=org/chasen/crfpp 9 | 10 | LIBS=-lcrfpp -lpthread 11 | INC=-I$(INCLUDE) -I$(INCLUDE)/linux 12 | 13 | all: 14 | $(CXX) -O3 -c -fpic $(TARGET)_wrap.cxx $(INC) 15 | $(CXX) -shared $(TARGET)_wrap.o -o lib$(TARGET).so $(LIBS) 16 | $(JAVAC) $(PACKAGE)/*.java 17 | $(JAVAC) test.java 18 | $(JAR) cfv $(TARGET).jar $(PACKAGE)/*.class 19 | 20 | test: 21 | env LD_LIBRARY_PATH=. $(JAVA) test 22 | 23 | clean: 24 | rm -fr *.jar *.o *.so *.class $(PACKAGE)/*.class 25 | 26 | cleanall: 27 | rm -fr $(TARGET).java *.cxx 28 | -------------------------------------------------------------------------------- /java/.am: -------------------------------------------------------------------------------- 1 | TARGET=MeCab 2 | JAVAC=javac 3 | JAVA=java 4 | JAR=jar 5 | CXX=c++ 6 | INCLUDE=/usr/lib/jvm/java-6-openjdk/include 7 | 8 | PACKAGE=org/chasen/mecab 9 | 10 | LIBS=`mecab-config --libs` 11 | INC=`mecab-config --cflags` -I$(INCLUDE) -I$(INCLUDE)/linux 12 | 13 | all: 14 | $(CXX) -O3 -c -fpic $(TARGET)_wrap.cxx $(INC) 15 | $(CXX) -shared $(TARGET)_wrap.o -o lib$(TARGET).so $(LIBS) 16 | $(JAVAC) $(PACKAGE)/*.java 17 | $(JAVAC) test.java 18 | $(JAR) cfv $(TARGET).jar $(PACKAGE)/*.class 19 | 20 | test: 21 | env LD_LIBRARY_PATH=. $(JAVA) test 22 | 23 | clean: 24 | rm -fr *.jar *.o *.so *.class $(PACKAGE)/*.class 25 | 26 | cleanall: 27 | rm -fr $(TARGET).java *.cxx 28 | -------------------------------------------------------------------------------- /path.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: path.cpp 1587 2007-02-12 09:00:36Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #include 9 | #include "path.h" 10 | #include "common.h" 11 | 12 | namespace CRFPP { 13 | 14 | void Path::calcExpectation(double *expected, double Z, size_t size) const { 15 | const double c = std::exp(lnode->alpha + cost + rnode->beta - Z); 16 | for (const int *f = fvector; *f != -1; ++f) { 17 | expected[*f + lnode->y * size + rnode->y] += c; 18 | } 19 | } 20 | 21 | void Path::add(Node *_lnode, Node *_rnode) { 22 | lnode = _lnode; 23 | rnode = _rnode; 24 | lnode->rpath.push_back(this); 25 | rnode->lpath.push_back(this); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /encoder.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: encoder.h 1588 2007-02-12 09:03:39Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_ENCODER_H_ 9 | #define CRFPP_ENCODER_H_ 10 | 11 | #include "common.h" 12 | 13 | namespace CRFPP { 14 | class Encoder { 15 | public: 16 | enum { CRF_L2, CRF_L1, MIRA }; 17 | bool learn(const char *, const char *, 18 | const char *, 19 | bool, size_t, size_t, 20 | double, double, 21 | unsigned short, 22 | unsigned short, int); 23 | 24 | bool convert(const char *text_file, 25 | const char* binary_file); 26 | 27 | const char* what() { return what_.str(); } 28 | 29 | private: 30 | whatlog what_; 31 | }; 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /example/JapaneseNE/template: -------------------------------------------------------------------------------- 1 | # Unigram 2 | U00:%x[-2,0] 3 | U01:%x[-1,0] 4 | U02:%x[0,0] 5 | U03:%x[1,0] 6 | U04:%x[2,0] 7 | U05:%x[-1,0]/%x[0,0] 8 | U06:%x[0,0]/%x[1,0] 9 | 10 | U10:%x[-2,1] 11 | U11:%x[-1,1] 12 | U12:%x[0,1] 13 | U13:%x[1,1] 14 | U14:%x[2,1] 15 | U15:%x[-2,1]/%x[-1,1] 16 | U16:%x[-1,1]/%x[0,1] 17 | U17:%x[0,1]/%x[1,1] 18 | U18:%x[1,1]/%x[2,1] 19 | 20 | U20:%x[-2,1]/%x[-1,1]/%x[0,1] 21 | U21:%x[-1,1]/%x[0,1]/%x[1,1] 22 | U22:%x[0,1]/%x[1,1]/%x[2,1] 23 | 24 | U30:%x[-2,2] 25 | U31:%x[-1,2] 26 | U32:%x[0,2] 27 | U33:%x[1,2] 28 | U34:%x[2,2] 29 | U35:%x[-2,2]/%x[-1,2] 30 | U36:%x[-1,2]/%x[0,2] 31 | U37:%x[0,2]/%x[1,2] 32 | U38:%x[1,2]/%x[2,2] 33 | 34 | U40:%x[-2,2]/%x[-1,2]/%x[0,2] 35 | U41:%x[-1,2]/%x[0,2]/%x[1,2] 36 | U42:%x[0,2]/%x[1,2]/%x[2,2] 37 | 38 | U50:%x[0,1]/%x[0,2] 39 | 40 | # Bigram 41 | B 42 | -------------------------------------------------------------------------------- /feature_cache.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: feature_cache.h 1588 2007-02-12 09:03:39Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_FEATURE_CACHE_H_ 9 | #define CRFPP_FEATURE_CACHE_H_ 10 | 11 | #include 12 | #include 13 | #include "freelist.h" 14 | 15 | namespace CRFPP { 16 | 17 | class FeatureCache: public std::vector { 18 | public: 19 | void clear() { 20 | std::vector::clear(); 21 | feature_freelist_.free(); 22 | } 23 | 24 | void add(const std::vector &); 25 | void shrink(std::map *); 26 | 27 | explicit FeatureCache(): feature_freelist_(8192 * 16) {} 28 | virtual ~FeatureCache() {} 29 | 30 | private: 31 | FreeList feature_freelist_; 32 | }; 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /java/org/chasen/crfpp/SWIGTYPE_p_int.java: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 1.3.31 4 | * 5 | * Do not make changes to this file unless you know what you are doing--modify 6 | * the SWIG interface file instead. 7 | * ----------------------------------------------------------------------------- */ 8 | 9 | package org.chasen.crfpp; 10 | 11 | public class SWIGTYPE_p_int { 12 | private long swigCPtr; 13 | 14 | protected SWIGTYPE_p_int(long cPtr, boolean futureUse) { 15 | swigCPtr = cPtr; 16 | } 17 | 18 | protected SWIGTYPE_p_int() { 19 | swigCPtr = 0; 20 | } 21 | 22 | protected static long getCPtr(SWIGTYPE_p_int obj) { 23 | return (obj == null) ? 0 : obj.swigCPtr; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /java/org/chasen/crfpp/SWIGTYPE_p_float.java: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 1.3.31 4 | * 5 | * Do not make changes to this file unless you know what you are doing--modify 6 | * the SWIG interface file instead. 7 | * ----------------------------------------------------------------------------- */ 8 | 9 | package org.chasen.crfpp; 10 | 11 | public class SWIGTYPE_p_float { 12 | private long swigCPtr; 13 | 14 | protected SWIGTYPE_p_float(long cPtr, boolean futureUse) { 15 | swigCPtr = cPtr; 16 | } 17 | 18 | protected SWIGTYPE_p_float() { 19 | swigCPtr = 0; 20 | } 21 | 22 | protected static long getCPtr(SWIGTYPE_p_float obj) { 23 | return (obj == null) ? 0 : obj.swigCPtr; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /java/org/chasen/crfpp/SWIGTYPE_p_p_char.java: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 2.0.4 4 | * 5 | * Do not make changes to this file unless you know what you are doing--modify 6 | * the SWIG interface file instead. 7 | * ----------------------------------------------------------------------------- */ 8 | 9 | package org.chasen.crfpp; 10 | 11 | public class SWIGTYPE_p_p_char { 12 | private long swigCPtr; 13 | 14 | protected SWIGTYPE_p_p_char(long cPtr, boolean futureUse) { 15 | swigCPtr = cPtr; 16 | } 17 | 18 | protected SWIGTYPE_p_p_char() { 19 | swigCPtr = 0; 20 | } 21 | 22 | protected static long getCPtr(SWIGTYPE_p_p_char obj) { 23 | return (obj == null) ? 0 : obj.swigCPtr; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /path.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: path.h 1595 2007-02-24 10:18:32Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_PATH_H_ 9 | #define CRFPP_PATH_H_ 10 | 11 | #include 12 | #include "node.h" 13 | 14 | namespace CRFPP { 15 | struct Node; 16 | 17 | struct Path { 18 | Node *rnode; 19 | Node *lnode; 20 | const int *fvector; 21 | double cost; 22 | 23 | Path() : rnode(0), lnode(0), fvector(0), cost(0.0) {} 24 | 25 | // for CRF 26 | void calcExpectation(double *expected, double, size_t) const; 27 | void add(Node *_lnode, Node *_rnode) ; 28 | 29 | void clear() { 30 | rnode = lnode = 0; 31 | fvector = 0; 32 | cost = 0.0; 33 | } 34 | }; 35 | 36 | typedef std::vector::const_iterator const_Path_iterator; 37 | } 38 | #endif 39 | -------------------------------------------------------------------------------- /mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | # Author: Noah Friedman 4 | # Created: 1993-05-16 5 | # Public domain 6 | 7 | # $Id: mkinstalldirs,v 1.13 1999/01/05 03:18:55 bje Exp $ 8 | 9 | errstatus=0 10 | 11 | for file 12 | do 13 | set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 14 | shift 15 | 16 | pathcomp= 17 | for d 18 | do 19 | pathcomp="$pathcomp$d" 20 | case "$pathcomp" in 21 | -* ) pathcomp=./$pathcomp ;; 22 | esac 23 | 24 | if test ! -d "$pathcomp"; then 25 | echo "mkdir $pathcomp" 26 | 27 | mkdir "$pathcomp" || lasterr=$? 28 | 29 | if test ! -d "$pathcomp"; then 30 | errstatus=$lasterr 31 | fi 32 | fi 33 | 34 | pathcomp="$pathcomp/" 35 | done 36 | done 37 | 38 | exit $errstatus 39 | 40 | # mkinstalldirs ends here 41 | -------------------------------------------------------------------------------- /swig/Makefile: -------------------------------------------------------------------------------- 1 | SWIG = swig 2 | PREFIX = CRFPP 3 | 4 | all: perl ruby python java 5 | 6 | clean: 7 | rm -f *.pm *.cxx *.py 8 | 9 | perl: 10 | $(SWIG) -perl -shadow -c++ $(PREFIX).i 11 | mv -f $(PREFIX)_wrap.cxx ../perl 12 | mv -f $(PREFIX).pm ../perl 13 | 14 | ruby: 15 | $(SWIG) -ruby -c++ $(PREFIX).i 16 | mv -f $(PREFIX)_wrap.cxx ../ruby/$(PREFIX)_wrap.cpp 17 | 18 | python: 19 | $(SWIG) -python -shadow -c++ $(PREFIX).i 20 | mv -f $(PREFIX)_wrap.cxx ../python 21 | mv -f $(PREFIX).py ../python 22 | 23 | csharp: 24 | $(SWIG) -csharp -namespace CRFPP -c++ $(PREFIX).i 25 | mv -f $(PREFIX)_wrap.cxx ../csharp 26 | mv -f *.cs ../csharp 27 | 28 | java: 29 | $(SWIG) -java -package org.chasen.crfpp -c++ $(PREFIX).i 30 | mkdir -p ../java/org/chasen/crfpp 31 | mv -f $(PREFIX)_wrap.cxx ../java 32 | # rm -fr exception.java SWIGTYPE_*.java 33 | mv -f *.java ../java/org/chasen/crfpp 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /feature_cache.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: feature_cache.cpp 1587 2007-02-12 09:00:36Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #include 9 | #include "feature_cache.h" 10 | 11 | namespace CRFPP { 12 | 13 | void FeatureCache::add(const std::vector &f) { 14 | int *p = feature_freelist_.alloc(f.size() + 1); 15 | std::copy(f.begin(), f.end(), p); 16 | p[f.size()] = -1; // sentinel 17 | this->push_back(p); 18 | } 19 | 20 | void FeatureCache::shrink(std::map *old2new) { 21 | for (size_t i = 0; i < size(); ++i) { 22 | std::vector newf; 23 | for (int *f = (*this)[i]; *f != -1; ++f) { 24 | std::map::iterator it = old2new->find(*f); 25 | if (it != old2new->end()) { 26 | newf.push_back(it->second); 27 | } 28 | } 29 | newf.push_back(-1); 30 | std::copy(newf.begin(), newf.end(), (*this)[i]); 31 | } 32 | return; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Makefile.msvc: -------------------------------------------------------------------------------- 1 | CC = cl 2 | CXXC = cl 3 | LINK=link 4 | CFLAGS = /O2 /GA /GL /Gy /Oi /Ob2 /nologo /W3 /EHsc /MT /wd4244 5 | LDFLAGS = /link /OPT:REF /OPT:ICF /LTCG /NXCOMPAT /DYNAMICBASE ADVAPI32.LIB 6 | DEFS = -D_CRT_SECURE_NO_DEPRECATE -DDLL_EXPORT \ 7 | -DUNICODE -D_UNICODE \ 8 | -DHAVE_WINDOWS_H -DVERSION="\"0.59\"" -DPACKAGE="\"CRF++\"" 9 | INC = -I. -I.. 10 | DEL = del 11 | 12 | OBJ = encoder.obj feature.obj feature_cache.obj libcrfpp.obj \ 13 | feature_index.obj node.obj param.obj path.obj tagger.obj lbfgs.obj 14 | 15 | .c.obj: 16 | $(CXXC) $(CFLAGS) $(INC) $(DEFS) -c $< 17 | 18 | .cpp.obj: 19 | $(CXXC) $(CFLAGS) $(INC) $(DEFS) -c $< 20 | 21 | .c.obj: 22 | $(CC) $(CFLAGS) $(INC) $(DEFS) -c $< 23 | 24 | all: libcrfpp crf_learn crf_test 25 | 26 | libcrfpp: $(OBJ) 27 | $(LINK) $(LDFLAGS) /out:$@.dll $(OBJ) /dll 28 | 29 | crf_learn: $(OBJ) crf_learn.obj 30 | $(LINK) $(LDFLAGS) /out:$@.exe crf_learn.obj libcrfpp.lib 31 | 32 | crf_test: $(OBJ) crf_test.obj 33 | $(LINK) $(LDFLAGS) /out:$@.exe crf_test.obj libcrfpp.lib 34 | 35 | clean: 36 | del *.obj crf_learn.exe crf_test.exe *.dll 37 | -------------------------------------------------------------------------------- /Makefile.msvc.in: -------------------------------------------------------------------------------- 1 | CC = cl 2 | CXXC = cl 3 | LINK=link 4 | CFLAGS = /O2 /GA /GL /Gy /Oi /Ob2 /nologo /W3 /EHsc /MT /wd4244 5 | LDFLAGS = /link /OPT:REF /OPT:ICF /LTCG /NXCOMPAT /DYNAMICBASE ADVAPI32.LIB 6 | DEFS = -D_CRT_SECURE_NO_DEPRECATE -DDLL_EXPORT \ 7 | -DUNICODE -D_UNICODE \ 8 | -DHAVE_WINDOWS_H -DVERSION="\"@VERSION@\"" -DPACKAGE="\"@PACKAGE@\"" 9 | INC = -I. -I.. 10 | DEL = del 11 | 12 | OBJ = encoder.obj feature.obj feature_cache.obj libcrfpp.obj \ 13 | feature_index.obj node.obj param.obj path.obj tagger.obj lbfgs.obj 14 | 15 | .c.obj: 16 | $(CXXC) $(CFLAGS) $(INC) $(DEFS) -c $< 17 | 18 | .cpp.obj: 19 | $(CXXC) $(CFLAGS) $(INC) $(DEFS) -c $< 20 | 21 | .c.obj: 22 | $(CC) $(CFLAGS) $(INC) $(DEFS) -c $< 23 | 24 | all: libcrfpp crf_learn crf_test 25 | 26 | libcrfpp: $(OBJ) 27 | $(LINK) $(LDFLAGS) /out:$@.dll $(OBJ) /dll 28 | 29 | crf_learn: $(OBJ) crf_learn.obj 30 | $(LINK) $(LDFLAGS) /out:$@.exe crf_learn.obj libcrfpp.lib 31 | 32 | crf_test: $(OBJ) crf_test.obj 33 | $(LINK) $(LDFLAGS) /out:$@.exe crf_test.obj libcrfpp.lib 34 | 35 | clean: 36 | del *.obj crf_learn.exe crf_test.exe *.dll 37 | -------------------------------------------------------------------------------- /node.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: node.cpp 1595 2007-02-24 10:18:32Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #include 9 | #include 10 | #include "node.h" 11 | #include "common.h" 12 | 13 | namespace CRFPP { 14 | 15 | void Node::calcAlpha() { 16 | alpha = 0.0; 17 | for (const_Path_iterator it = lpath.begin(); it != lpath.end(); ++it) { 18 | alpha = logsumexp(alpha, 19 | (*it)->cost +(*it)->lnode->alpha, 20 | (it == lpath.begin())); 21 | } 22 | alpha += cost; 23 | } 24 | 25 | void Node::calcBeta() { 26 | beta = 0.0; 27 | for (const_Path_iterator it = rpath.begin(); it != rpath.end(); ++it) { 28 | beta = logsumexp(beta, 29 | (*it)->cost +(*it)->rnode->beta, 30 | (it == rpath.begin())); 31 | } 32 | beta += cost; 33 | } 34 | 35 | void Node::calcExpectation(double *expected, double Z, size_t size) const { 36 | const double c = std::exp(alpha + beta - cost - Z); 37 | for (const int *f = fvector; *f != -1; ++f) { 38 | expected[*f + y] += c; 39 | } 40 | for (const_Path_iterator it = lpath.begin(); it != lpath.end(); ++it) { 41 | (*it)->calcExpectation(expected, Z, size); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /swig/CRFPP.i: -------------------------------------------------------------------------------- 1 | %module CRFPP 2 | %include exception.i 3 | %{ 4 | #include "crfpp.h" 5 | %} 6 | 7 | %newobject surface; 8 | 9 | %exception { 10 | try { $action } 11 | catch (char *e) { SWIG_exception (SWIG_RuntimeError, e); } 12 | catch (const char *e) { SWIG_exception (SWIG_RuntimeError, (char*)e); } 13 | } 14 | 15 | %feature("notabstract") CRFPP::Model; 16 | %feature("notabstract") CRFPP::Tagger; 17 | %ignore CRFPP::createModel; 18 | %ignore CRFPP::createModelFromArray; 19 | %ignore CRFPP::createTagger; 20 | %ignore CRFPP::getTaggerError; 21 | %ignore CRFPP::getLastError; 22 | 23 | %extend CRFPP::Model { Model(const char *arg); } 24 | %extend CRFPP::Tagger { Tagger(const char *arg); } 25 | 26 | %{ 27 | 28 | void delete_CRFPP_Model (CRFPP::Model *t) { 29 | delete t; 30 | t = 0; 31 | } 32 | 33 | CRFPP::Model* new_CRFPP_Model(const char *arg) { 34 | CRFPP::Model *tagger = CRFPP::createModel(arg); 35 | if (!tagger) throw CRFPP::getLastError(); 36 | return tagger; 37 | } 38 | 39 | void delete_CRFPP_Tagger (CRFPP::Tagger *t) { 40 | delete t; 41 | t = 0; 42 | } 43 | 44 | CRFPP::Tagger* new_CRFPP_Tagger (const char *arg) { 45 | CRFPP::Tagger *tagger = CRFPP::createTagger(arg); 46 | if (!tagger) throw CRFPP::getLastError(); 47 | return tagger; 48 | } 49 | 50 | %} 51 | 52 | %include ../crfpp.h 53 | %include version.h 54 | -------------------------------------------------------------------------------- /doxygen/tabs.css: -------------------------------------------------------------------------------- 1 | .tabs, .tabs2, .tabs3 { 2 | background-image: url('tab_b.png'); 3 | width: 100%; 4 | z-index: 101; 5 | font-size: 13px; 6 | } 7 | 8 | .tabs2 { 9 | font-size: 10px; 10 | } 11 | .tabs3 { 12 | font-size: 9px; 13 | } 14 | 15 | .tablist { 16 | margin: 0; 17 | padding: 0; 18 | display: table; 19 | } 20 | 21 | .tablist li { 22 | float: left; 23 | display: table-cell; 24 | background-image: url('tab_b.png'); 25 | line-height: 36px; 26 | list-style: none; 27 | } 28 | 29 | .tablist a { 30 | display: block; 31 | padding: 0 20px; 32 | font-weight: bold; 33 | background-image:url('tab_s.png'); 34 | background-repeat:no-repeat; 35 | background-position:right; 36 | color: #283A5D; 37 | text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.9); 38 | text-decoration: none; 39 | outline: none; 40 | } 41 | 42 | .tabs3 .tablist a { 43 | padding: 0 10px; 44 | } 45 | 46 | .tablist a:hover { 47 | background-image: url('tab_h.png'); 48 | background-repeat:repeat-x; 49 | color: #fff; 50 | text-shadow: 0px 1px 1px rgba(0, 0, 0, 1.0); 51 | text-decoration: none; 52 | } 53 | 54 | .tablist li.current a { 55 | background-image: url('tab_a.png'); 56 | background-repeat:repeat-x; 57 | color: #fff; 58 | text-shadow: 0px 1px 1px rgba(0, 0, 0, 1.0); 59 | } 60 | -------------------------------------------------------------------------------- /stream_wrapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: stream_wrapper.h 1588 2007-02-12 09:03:39Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_STREAM_WRAPPER_H_ 9 | #define CRFPP_STREAM_WRAPPER_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "common.h" 15 | 16 | namespace CRFPP { 17 | 18 | class istream_wrapper { 19 | private: 20 | std::istream* is; 21 | public: 22 | std::istream &operator*() const { return *is; } 23 | std::istream *operator->() const { return is; } 24 | std::istream *get() { return is; } 25 | explicit istream_wrapper(const char* filename): is(0) { 26 | if (std::strcmp(filename, "-") == 0) 27 | is = &std::cin; 28 | else 29 | is = new std::ifstream(WPATH(filename)); 30 | } 31 | 32 | ~istream_wrapper() { 33 | if (is != &std::cin) delete is; 34 | } 35 | }; 36 | 37 | class ostream_wrapper { 38 | private: 39 | std::ostream* os; 40 | public: 41 | std::ostream &operator*() const { return *os; } 42 | std::ostream *operator->() const { return os; } 43 | std::ostream *get() { return os; } 44 | explicit ostream_wrapper(const char* filename): os(0) { 45 | if (std::strcmp(filename, "-") == 0) 46 | os = &std::cout; 47 | else 48 | os = new std::ofstream(WPATH(filename)); 49 | } 50 | 51 | ~ostream_wrapper() { 52 | if (os != &std::cout) delete os; 53 | } 54 | }; 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /BSD: -------------------------------------------------------------------------------- 1 | Copyright (c) 2005-2007, Taku Kudo 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above 8 | copyright notice, this list of conditions and the 9 | following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the 13 | following disclaimer in the documentation and/or other 14 | materials provided with the distribution. 15 | 16 | * Neither the name of Taku Kudo nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 26 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 27 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /java/org/chasen/crfpp/Model.java: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 2.0.4 4 | * 5 | * Do not make changes to this file unless you know what you are doing--modify 6 | * the SWIG interface file instead. 7 | * ----------------------------------------------------------------------------- */ 8 | 9 | package org.chasen.crfpp; 10 | 11 | public class Model { 12 | private long swigCPtr; 13 | protected boolean swigCMemOwn; 14 | 15 | public Model(long cPtr, boolean cMemoryOwn) { 16 | swigCMemOwn = cMemoryOwn; 17 | swigCPtr = cPtr; 18 | } 19 | 20 | public static long getCPtr(Model obj) { 21 | return (obj == null) ? 0 : obj.swigCPtr; 22 | } 23 | 24 | protected void finalize() { 25 | delete(); 26 | } 27 | 28 | public synchronized void delete() { 29 | if (swigCPtr != 0) { 30 | if (swigCMemOwn) { 31 | swigCMemOwn = false; 32 | CRFPPJNI.delete_Model(swigCPtr); 33 | } 34 | swigCPtr = 0; 35 | } 36 | } 37 | 38 | public String getTemplate() { 39 | return CRFPPJNI.Model_getTemplate(swigCPtr, this); 40 | } 41 | 42 | public Tagger createTagger() { 43 | long cPtr = CRFPPJNI.Model_createTagger(swigCPtr, this); 44 | return (cPtr == 0) ? null : new Tagger(cPtr, false); 45 | } 46 | 47 | public String what() { 48 | return CRFPPJNI.Model_what(swigCPtr, this); 49 | } 50 | 51 | public Model(String arg) { 52 | this(CRFPPJNI.new_Model(arg), true); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /timer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: timer.h 1588 2007-02-12 09:03:39Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_TIMER_H_ 9 | #define CRFPP_TIMER_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace CRFPP { 17 | 18 | class timer { 19 | public: 20 | explicit timer() { start_time_ = std::clock(); } 21 | void restart() { start_time_ = std::clock(); } 22 | double elapsed() const { 23 | return static_cast(std::clock() - start_time_) / CLOCKS_PER_SEC; 24 | } 25 | 26 | double elapsed_max() const { 27 | // return (static_cast(std::numeric_limits::max()) 28 | // - static_cast(start_time_)) / 29 | // static_cast(CLOCKS_PER_SEC); 30 | return 0.0; 31 | } 32 | 33 | double elapsed_min() const { 34 | return static_cast(1.0 / CLOCKS_PER_SEC); 35 | } 36 | 37 | private: 38 | std::clock_t start_time_; 39 | }; 40 | 41 | class progress_timer : public timer { 42 | public: 43 | explicit progress_timer(std::ostream & os = std::cout) : os_(os) {} 44 | virtual ~progress_timer() { 45 | std::istream::fmtflags old_flags = os_.setf(std::istream::fixed, 46 | std::istream::floatfield); 47 | std::streamsize old_prec = os_.precision(2); 48 | os_ << elapsed() << " s\n" << std::endl; 49 | os_.flags(old_flags); 50 | os_.precision(old_prec); 51 | } 52 | 53 | private: 54 | std::ostream & os_; 55 | }; 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /freelist.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: freelist.h 1588 2007-02-12 09:03:39Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_FREELIST_H_ 9 | #define CRFPP_FREELIST_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace CRFPP { 15 | template 16 | class Length { 17 | public: 18 | size_t operator()(const T *str) const { return 1; } 19 | }; 20 | 21 | class charLength { 22 | public: 23 | size_t operator()(const char *str) const { return strlen(str) + 1; } 24 | }; 25 | 26 | template > 27 | class FreeList { 28 | private: 29 | std::vector freeList; 30 | size_t pi; 31 | size_t li; 32 | size_t size; 33 | 34 | public: 35 | void free() { li = pi = 0; } 36 | 37 | T* alloc(size_t len = 1) { 38 | if ((pi + len) >= size) { 39 | li++; 40 | pi = 0; 41 | } 42 | if (li == freeList.size()) { 43 | freeList.push_back(new T[size]); 44 | } 45 | T* r = freeList[li] + pi; 46 | pi += len; 47 | return r; 48 | } 49 | 50 | T* dup(T *src, size_t len = 0) { 51 | if (!len) len = LengthFunc () (src); 52 | T *p = alloc(len); 53 | if (src == 0) memset (p, 0, len * sizeof (T)); 54 | else memcpy(p, src, len * sizeof(T)); 55 | return p; 56 | } 57 | 58 | void set_size(size_t n) { size = n; } 59 | 60 | explicit FreeList(size_t _size): pi(0), li(0), size(_size) {} 61 | explicit FreeList(): pi(0), li(0), size(0) {} 62 | 63 | virtual ~FreeList() { 64 | for (li = 0; li < freeList.size(); ++li) { 65 | delete [] freeList[li]; 66 | } 67 | } 68 | }; 69 | 70 | typedef FreeList StrFreeList; 71 | } 72 | #endif 73 | -------------------------------------------------------------------------------- /doxygen/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | CRF++: Main Page 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
CRF++ 26 | 27 |
28 | 29 |
36 |
37 | 38 | 39 | 47 |
48 |
49 |
50 |
CRF++ Documentation
51 |
52 |
53 |
54 | 55 | 56 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /thread.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: thread.h 1588 2007-02-12 09:03:39Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_THREAD_H_ 9 | #define CRFPP_THREAD_H_ 10 | 11 | #ifdef HAVE_PTHREAD_H 12 | #include 13 | #else 14 | #ifdef _WIN32 15 | #include 16 | #include 17 | #endif 18 | #endif 19 | 20 | #if defined HAVE_PTHREAD_H 21 | #define CRFPP_USE_THREAD 1 22 | #endif 23 | 24 | #if(defined(_WIN32) && !defined (__CYGWIN__)) 25 | #define CRFPP_USE_THREAD 1 26 | #define BEGINTHREAD(src, stack, func, arg, flag, id) \ 27 | (HANDLE)_beginthreadex((void *)(src), (unsigned)(stack), \ 28 | (unsigned(_stdcall *)(void *))(func), (void *)(arg), \ 29 | (unsigned)(flag), (unsigned *)(id)) 30 | #endif 31 | 32 | namespace CRFPP { 33 | 34 | class thread { 35 | private: 36 | #ifdef HAVE_PTHREAD_H 37 | pthread_t hnd_; 38 | #else 39 | #ifdef _WIN32 40 | HANDLE hnd_; 41 | #endif 42 | #endif 43 | 44 | public: 45 | static void* wrapper(void *ptr) { 46 | thread *p = static_cast(ptr); 47 | p->run(); 48 | return 0; 49 | } 50 | 51 | virtual void run() {} 52 | 53 | void start() { 54 | #ifdef HAVE_PTHREAD_H 55 | pthread_create(&hnd_, 0, &thread::wrapper, 56 | static_cast(this)); 57 | 58 | #else 59 | #ifdef _WIN32 60 | DWORD id; 61 | hnd_ = BEGINTHREAD(0, 0, &thread::wrapper, this, 0, &id); 62 | #else 63 | run(); 64 | #endif 65 | #endif 66 | } 67 | 68 | void join() { 69 | #ifdef HAVE_PTHREAD_H 70 | pthread_join(hnd_, 0); 71 | #else 72 | #ifdef _WIN32 73 | WaitForSingleObject(hnd_, INFINITE); 74 | CloseHandle(hnd_); 75 | #endif 76 | #endif 77 | } 78 | 79 | virtual ~thread() {} 80 | }; 81 | } 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /node.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: node.h 1595 2007-02-24 10:18:32Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_NODE_H_ 9 | #define CRFPP_NODE_H_ 10 | 11 | #include 12 | #include 13 | #include "path.h" 14 | #include "common.h" 15 | 16 | #define LOG2 0.69314718055 17 | #define MINUS_LOG_EPSILON 50 18 | 19 | namespace CRFPP { 20 | // log(exp(x) + exp(y)); 21 | // this can be used recursivly 22 | // e.g., log(exp(log(exp(x) + exp(y))) + exp(z)) = 23 | // log(exp (x) + exp(y) + exp(z)) 24 | inline double logsumexp(double x, double y, bool flg) { 25 | if (flg) return y; // init mode 26 | const double vmin = std::min(x, y); 27 | const double vmax = std::max(x, y); 28 | if (vmax > vmin + MINUS_LOG_EPSILON) { 29 | return vmax; 30 | } else { 31 | return vmax + std::log(std::exp(vmin - vmax) + 1.0); 32 | } 33 | } 34 | 35 | struct Path; 36 | 37 | struct Node { 38 | unsigned int x; 39 | unsigned short int y; 40 | double alpha; 41 | double beta; 42 | double cost; 43 | double bestCost; 44 | Node *prev; 45 | const int *fvector; 46 | std::vector lpath; 47 | std::vector rpath; 48 | 49 | void calcAlpha(); 50 | void calcBeta(); 51 | void calcExpectation(double *expected, double, size_t) const; 52 | 53 | void clear() { 54 | x = y = 0; 55 | alpha = beta = cost = 0.0; 56 | prev = 0; 57 | fvector = 0; 58 | lpath.clear(); 59 | rpath.clear(); 60 | } 61 | 62 | void shrink() { 63 | std::vector(lpath).swap(lpath); 64 | std::vector(rpath).swap(rpath); 65 | } 66 | 67 | Node() : x(0), y(0), alpha(0.0), beta(0.0), 68 | cost(0.0), bestCost(0.0), prev(0), fvector(0) {} 69 | }; 70 | } 71 | #endif 72 | -------------------------------------------------------------------------------- /python/test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | import CRFPP 4 | import sys 5 | 6 | try: 7 | # -v 3: access deep information like alpha,beta,prob 8 | # -nN: enable nbest output. N should be >= 2 9 | tagger = CRFPP.Tagger("-m ../model -v 3 -n2") 10 | 11 | # clear internal context 12 | tagger.clear() 13 | 14 | # add context 15 | tagger.add("Confidence NN") 16 | tagger.add("in IN") 17 | tagger.add("the DT") 18 | tagger.add("pound NN") 19 | tagger.add("is VBZ") 20 | tagger.add("widely RB") 21 | tagger.add("expected VBN") 22 | tagger.add("to TO") 23 | tagger.add("take VB") 24 | tagger.add("another DT") 25 | tagger.add("sharp JJ") 26 | tagger.add("dive NN") 27 | tagger.add("if IN") 28 | tagger.add("trade NN") 29 | tagger.add("figures NNS") 30 | tagger.add("for IN") 31 | tagger.add("September NNP") 32 | 33 | print "column size: " , tagger.xsize() 34 | print "token size: " , tagger.size() 35 | print "tag size: " , tagger.ysize() 36 | 37 | print "tagset information:" 38 | ysize = tagger.ysize() 39 | for i in range(0, ysize-1): 40 | print "tag " , i , " " , tagger.yname(i) 41 | 42 | # parse and change internal stated as 'parsed' 43 | tagger.parse() 44 | 45 | print "conditional prob=" , tagger.prob(), " log(Z)=" , tagger.Z() 46 | 47 | size = tagger.size() 48 | xsize = tagger.xsize() 49 | for i in range(0, (size - 1)): 50 | for j in range(0, (xsize-1)): 51 | print tagger.x(i, j) , "\t", 52 | print tagger.y2(i) , "\t", 53 | print "Details", 54 | for j in range(0, (ysize-1)): 55 | print "\t" , tagger.yname(j) , "/prob=" , tagger.prob(i,j),"/alpha=" , tagger.alpha(i, j),"/beta=" , tagger.beta(i, j), 56 | print "\n", 57 | 58 | print "nbest outputs:" 59 | for n in range(0, 9): 60 | if (not tagger.next()): 61 | continue 62 | print "nbest n=" , n , "\tconditional prob=" , tagger.prob() 63 | # you can access any information using tagger.y()... 64 | 65 | print "Done" 66 | 67 | except RuntimeError, e: 68 | print "RuntimeError: ", e, 69 | -------------------------------------------------------------------------------- /ruby/test.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | require 'CRFPP' 4 | 5 | begin 6 | # -v 3: access deep information like alpha,beta,prob 7 | # -nN: enable nbest output. N should be >= 2 8 | tagger = CRFPP::Tagger.new("-m ../model -v 3 -n2") 9 | 10 | # clear internal context 11 | tagger.clear() 12 | 13 | # add context 14 | tagger.add("Confidence NN") 15 | tagger.add("in IN") 16 | tagger.add("the DT") 17 | tagger.add("pound NN") 18 | tagger.add("is VBZ") 19 | tagger.add("widely RB") 20 | tagger.add("expected VBN") 21 | tagger.add("to TO") 22 | tagger.add("take VB") 23 | tagger.add("another DT") 24 | tagger.add("sharp JJ") 25 | tagger.add("dive NN") 26 | tagger.add("if IN") 27 | tagger.add("trade NN") 28 | tagger.add("figures NNS") 29 | tagger.add("for IN") 30 | tagger.add("September NNP") 31 | 32 | print "column size: " , tagger.xsize() , "\n" 33 | print "token size: " , tagger.size() , "\n" 34 | print "tag size: " , tagger.ysize() , "\n" 35 | 36 | print "tagset information:" , "\n" 37 | ysize = tagger.ysize() 38 | for i in 0..(ysize-1) 39 | print "tag " , i , " " , tagger.yname(i) , "\n" 40 | end 41 | 42 | # parse and change internal stated as 'parsed' 43 | die if !tagger.parse() 44 | 45 | print "conditional prob=" , tagger.prob(), " log(Z)=" , tagger.Z() , "\n" 46 | 47 | size = tagger.size() 48 | xsize = tagger.xsize() 49 | for i in 0..(size - 1) 50 | for j in 0..(xsize-1) 51 | print tagger.x(i, j) , "\t" 52 | end 53 | print tagger.y2(i) , "\t" 54 | print "\n" 55 | print "Details" 56 | for j in 0..(ysize-1) 57 | print "\t" , tagger.yname(j) , "/prob=" , tagger.prob(i,j),"/alpha=" , tagger.alpha(i, j),"/beta=" , tagger.beta(i, j) 58 | print "\n" 59 | end 60 | end 61 | 62 | 63 | print "nbest outputs:" , "\n" 64 | for n in 0..9 65 | last if !tagger.next() 66 | print "nbest n=" , n , "\tconditional prob=" , tagger.prob() , "\n" 67 | # you can access any information using tagger.y()... 68 | end 69 | 70 | print "Done" , "\n" 71 | 72 | rescue 73 | print "RuntimeError: ", $!, "\n" 74 | end 75 | -------------------------------------------------------------------------------- /perl/test.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use lib "../src/.libs"; 4 | use lib $ENV{PWD} . "/blib/lib"; 5 | use lib $ENV{PWD} . "/blib/arch"; 6 | use CRFPP; 7 | 8 | print $CRFPP::VERSION, "\n"; 9 | 10 | # -v 3: access deep information like alpha,beta,prob 11 | # -nN: enable nbest output. N should be >= 2 12 | my $tagger = new CRFPP::Tagger("-m ../model -v 3 -n2"); 13 | 14 | # clear internal context 15 | $tagger->clear(); 16 | 17 | # add context 18 | $tagger->add("Confidence NN"); 19 | $tagger->add("in IN"); 20 | $tagger->add("the DT"); 21 | $tagger->add("pound NN"); 22 | $tagger->add("is VBZ"); 23 | $tagger->add("widely RB"); 24 | $tagger->add("expected VBN"); 25 | $tagger->add("to TO"); 26 | $tagger->add("take VB"); 27 | $tagger->add("another DT"); 28 | $tagger->add("sharp JJ"); 29 | $tagger->add("dive NN"); 30 | $tagger->add("if IN"); 31 | $tagger->add("trade NN"); 32 | $tagger->add("figures NNS"); 33 | $tagger->add("for IN"); 34 | $tagger->add("September NNP"); 35 | 36 | print "column size: " , $tagger->xsize() , "\n"; 37 | print "token size: " , $tagger->size() , "\n"; 38 | print "tag size: " , $tagger->ysize() , "\n"; 39 | 40 | print "tagset information:" , "\n"; 41 | for (my $i = 0; $i < $tagger->ysize(); ++$i) { 42 | print "tag " , $i , " " , $tagger->yname($i) , "\n"; 43 | } 44 | 45 | # parse and change internal stated as 'parsed' 46 | die if (!$tagger->parse()); 47 | 48 | print "conditional prob=" , $tagger->prob(), " log(Z)=" , $tagger->Z() , "\n"; 49 | 50 | for (my $i = 0; $i < $tagger->size(); ++$i) { 51 | for (my $j = 0; $j < $tagger->xsize(); ++$j) { 52 | print $tagger->x($i, $j) , "\t"; 53 | } 54 | print $tagger->y2($i) , "\t"; 55 | print "\n"; 56 | print "Details"; 57 | for (my $j = 0; $j < $tagger->ysize(); ++$j) { 58 | print "\t" , $tagger->yname($j) , "/prob=" , $tagger->prob($i,$j) 59 | ,"/alpha=" , $tagger->alpha($i, $j) 60 | ,"/beta=" , $tagger->beta($i, $j); 61 | } 62 | print "\n"; 63 | } 64 | 65 | print "nbest outputs:" , "\n"; 66 | for (my $n = 0; $n < 10; ++$n) { 67 | last if (! $tagger->next()); 68 | print "nbest n=" , $n , "\tconditional prob=" , $tagger->prob() , "\n"; 69 | # you can access any information using $tagger->y()... 70 | } 71 | 72 | print "Done" , "\n"; 73 | -------------------------------------------------------------------------------- /doxygen/namespaces.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | CRF++: Namespace List 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
CRF++ 26 | 27 |
28 | 29 |
36 |
37 | 38 | 39 | 47 | 53 |
54 |
55 |
56 |
Namespace List
57 |
58 |
59 |
Here is a list of all namespaces with brief descriptions:
60 | 61 |
CRFPP
62 |
63 | 64 | 65 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /doxygen/files.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | CRF++: File List 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
CRF++ 26 | 27 |
28 | 29 |
36 |
37 | 38 | 39 | 47 | 53 |
54 |
55 |
56 |
File List
57 |
58 |
59 |
Here is a list of all files with brief descriptions:
60 | 61 |
/home/taku/proj/crfpp/crfpp.h [code]
62 |
63 | 64 | 65 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /doxygen/annotated.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | CRF++: Class List 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
CRF++ 26 | 27 |
28 | 29 |
36 |
37 | 38 | 39 | 47 | 53 |
54 |
55 |
56 |
Class List
57 |
58 |
59 |
Here are the classes, structs, unions and interfaces with brief descriptions:
60 | 61 | 62 |
CRFPP::Model
CRFPP::Tagger
63 |
64 | 65 | 66 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /java/test.java: -------------------------------------------------------------------------------- 1 | import org.chasen.crfpp.Tagger; 2 | 3 | public class test { 4 | 5 | public static void main(String[] argv) { 6 | Tagger tagger = new Tagger("-m ../model -v 3 -n2"); 7 | // clear internal context 8 | tagger.clear(); 9 | 10 | // add context 11 | tagger.add("Confidence NN"); 12 | tagger.add("in IN"); 13 | tagger.add("the DT"); 14 | tagger.add("pound NN"); 15 | tagger.add("is VBZ"); 16 | tagger.add("widely RB"); 17 | tagger.add("expected VBN"); 18 | tagger.add("to TO"); 19 | tagger.add("take VB"); 20 | tagger.add("another DT"); 21 | tagger.add("sharp JJ"); 22 | tagger.add("dive NN"); 23 | tagger.add("if IN"); 24 | tagger.add("trade NN"); 25 | tagger.add("figures NNS"); 26 | tagger.add("for IN"); 27 | tagger.add("September NNP"); 28 | 29 | System.out.println("column size: " + tagger.xsize()); 30 | System.out.println("token size: " + tagger.size()); 31 | System.out.println("tag size: " + tagger.ysize()); 32 | 33 | System.out.println("tagset information:"); 34 | for (int i = 0; i < tagger.ysize(); ++i) { 35 | System.out.println("tag " + i + " " + tagger.yname(i)); 36 | } 37 | 38 | // parse and change internal stated as 'parsed' 39 | if (!tagger.parse()) 40 | return; 41 | 42 | System.out.println("conditional prob=" + tagger.prob() 43 | + " log(Z)=" + tagger.Z()); 44 | 45 | for (int i = 0; i < tagger.size(); ++i) { 46 | for (int j = 0; j < tagger.xsize(); ++j) { 47 | System.out.print(tagger.x(i, j) + "\t"); 48 | } 49 | System.out.print(tagger.y2(i) + "\t"); 50 | System.out.print("\n"); 51 | 52 | System.out.print("Details"); 53 | for (int j = 0; j < tagger.ysize(); ++j) { 54 | System.out.print("\t" + tagger.yname(j) + "/prob=" + tagger.prob(i,j) 55 | + "/alpha=" + tagger.alpha(i, j) 56 | + "/beta=" + tagger.beta(i, j)); 57 | } 58 | System.out.print("\n"); 59 | } 60 | 61 | // when -n20 is specified, you can access nbest outputs 62 | System.out.println("nbest outputs:"); 63 | for (int n = 0; n < 10; ++n) { 64 | if (! tagger.next()) break; 65 | System.out.println("nbest n=" + n + "\tconditional prob=" + tagger.prob()); 66 | // you can access any information using tagger.y()... 67 | } 68 | System.out.println("Done"); 69 | } 70 | 71 | static { 72 | try { 73 | System.loadLibrary("CRFPP"); 74 | } catch (UnsatisfiedLinkError e) { 75 | System.err.println("Cannot load the example native code.\nMake sure your LD_LIBRARY_PATH contains \'.\'\n" + e); 76 | System.exit(1); 77 | } 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /doxygen/globals_type.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | CRF++: File Members 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
CRF++ 26 | 27 |
28 | 29 |
36 |
37 | 38 | 39 | 47 | 53 | 61 |
62 |
63 |  
    64 |
  • crfpp_model_t 65 | : crfpp.h 66 |
  • 67 |
  • crfpp_t 68 | : crfpp.h 69 |
  • 70 |
71 |
72 | 73 | 74 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /sdk/example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "crfpp.h" 3 | 4 | // c++ -O3 example.cpp -lcrfpp 5 | 6 | int main(int argc, char **argv) { 7 | 8 | // -v 3: access deep information like alpha,beta,prob 9 | // -nN: enable nbest output. N should be >= 2 10 | CRFPP::Tagger *tagger = 11 | CRFPP::createTagger("-m model -v 3 -n2"); 12 | 13 | if (!tagger) { 14 | std::cerr << CRFPP::getTaggerError() << std::endl; 15 | return -1; 16 | } 17 | 18 | // clear internal context 19 | tagger->clear(); 20 | 21 | // add context 22 | tagger->add("Confidence NN"); 23 | tagger->add("in IN"); 24 | tagger->add("the DT"); 25 | tagger->add("pound NN"); 26 | tagger->add("is VBZ"); 27 | tagger->add("widely RB"); 28 | tagger->add("expected VBN"); 29 | tagger->add("to TO"); 30 | tagger->add("take VB"); 31 | tagger->add("another DT"); 32 | tagger->add("sharp JJ"); 33 | tagger->add("dive NN"); 34 | tagger->add("if IN"); 35 | tagger->add("trade NN"); 36 | tagger->add("figures NNS"); 37 | tagger->add("for IN"); 38 | tagger->add("September NNP"); 39 | 40 | std::cout << "column size: " << tagger->xsize() << std::endl; 41 | std::cout << "token size: " << tagger->size() << std::endl; 42 | std::cout << "tag size: " << tagger->ysize() << std::endl; 43 | 44 | std::cout << "tagset information:" << std::endl; 45 | for (size_t i = 0; i < tagger->ysize(); ++i) { 46 | std::cout << "tag " << i << " " << tagger->yname(i) << std::endl; 47 | } 48 | 49 | // parse and change internal stated as 'parsed' 50 | if (! tagger->parse()) return -1; 51 | 52 | std::cout << "conditional prob=" << tagger->prob() 53 | << " log(Z)=" << tagger->Z() << std::endl; 54 | 55 | for (size_t i = 0; i < tagger->size(); ++i) { 56 | for (size_t j = 0; j < tagger->xsize(); ++j) { 57 | std::cout << tagger->x(i, j) << '\t'; 58 | } 59 | std::cout << tagger->y2(i) << '\t'; 60 | std::cout << std::endl; 61 | 62 | std::cout << "Details"; 63 | for (size_t j = 0; j < tagger->ysize(); ++j) { 64 | std::cout << '\t' << tagger->yname(j) << "/prob=" << tagger->prob(i,j) 65 | << "/alpha=" << tagger->alpha(i, j) 66 | << "/beta=" << tagger->beta(i, j); 67 | } 68 | std::cout << std::endl; 69 | } 70 | 71 | // when -n20 is specified, you can access nbest outputs 72 | std::cout << "nbest outputs:" << std::endl; 73 | for (size_t n = 0; n < 10; ++n) { 74 | if (! tagger->next()) break; 75 | std::cout << "nbest n=" << n << "\tconditional prob=" << tagger->prob() << std::endl; 76 | // you can access any information using tagger->y()... 77 | } 78 | std::cout << "Done" << std::endl; 79 | 80 | delete tagger; 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /param.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: param.h 1588 2007-02-12 09:03:39Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_PARAM_H__ 9 | #define CRFPP_PARAM_H__ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "scoped_ptr.h" 16 | #include "common.h" 17 | 18 | namespace CRFPP { 19 | 20 | namespace { 21 | template 22 | Target lexical_cast(Source arg) { 23 | std::stringstream interpreter; 24 | Target result; 25 | if (!(interpreter << arg) || !(interpreter >> result) || 26 | !(interpreter >> std::ws).eof()) { 27 | scoped_ptr r(new Target()); // return default value 28 | return *r; 29 | } 30 | return result; 31 | } 32 | 33 | template <> 34 | std::string lexical_cast(std::string arg) { 35 | return arg; 36 | } 37 | } 38 | 39 | struct Option { 40 | const char *name; 41 | char short_name; 42 | const char *default_value; 43 | const char *arg_description; 44 | const char *description; 45 | }; 46 | 47 | class Param { 48 | private: 49 | std::map conf_; 50 | std::vector rest_; 51 | std::string system_name_; 52 | std::string help_; 53 | std::string version_; 54 | whatlog what_; 55 | 56 | public: 57 | bool open(int argc, char **argv, const Option *opt); 58 | bool open(const char *arg, const Option *opt); 59 | bool load(const char *filename); 60 | void clear(); 61 | const std::vector& rest_args() const { return rest_; } 62 | 63 | const char* program_name() const { return system_name_.c_str(); } 64 | const char *what() { return what_.str(); } 65 | const char* help() const { return help_.c_str(); } 66 | const char* version() const { return version_.c_str(); } 67 | int help_version() const; 68 | 69 | template 70 | T get(const char *key) const { 71 | std::map::const_iterator it = conf_.find(key); 72 | if (it == conf_.end()) { 73 | scoped_ptr r(new T()); 74 | return *r; 75 | } 76 | return lexical_cast(it->second); 77 | } 78 | 79 | template 80 | void set(const char* key, const T &value, 81 | bool rewrite = true) { 82 | std::string key2 = std::string(key); 83 | if (rewrite || (!rewrite && conf_.find(key2) == conf_.end())) 84 | conf_[key2] = lexical_cast(value); 85 | } 86 | 87 | void dump_config(std::ostream *os) const; 88 | 89 | explicit Param() {} 90 | virtual ~Param() {} 91 | }; 92 | } 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /scoped_ptr.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: scoped_ptr.h 1588 2007-02-12 09:03:39Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_SCOPED_PTR_H_ 9 | #define CRFPP_SCOPED_PTR_H_ 10 | 11 | #include 12 | #include 13 | 14 | namespace CRFPP { 15 | 16 | template class scoped_ptr { 17 | private: 18 | T * ptr_; 19 | scoped_ptr(scoped_ptr const &); 20 | scoped_ptr & operator=(scoped_ptr const &); 21 | typedef scoped_ptr this_type; 22 | 23 | public: 24 | typedef T element_type; 25 | explicit scoped_ptr(T * p = 0): ptr_(p) {} 26 | virtual ~scoped_ptr() { delete ptr_; } 27 | void reset(T * p = 0) { 28 | delete ptr_; 29 | ptr_ = p; 30 | } 31 | T & operator*() const { return *ptr_; } 32 | T * operator->() const { return ptr_; } 33 | T * get() const { return ptr_; } 34 | }; 35 | 36 | template class scoped_fixed_array { 37 | private: 38 | T * ptr_; 39 | size_t size_; 40 | scoped_fixed_array(scoped_fixed_array const &); 41 | scoped_fixed_array & operator= (scoped_fixed_array const &); 42 | typedef scoped_fixed_array this_type; 43 | 44 | public: 45 | typedef T element_type; 46 | explicit scoped_fixed_array() 47 | : ptr_(new T[N]), size_(N) {} 48 | virtual ~scoped_fixed_array() { delete [] ptr_; } 49 | size_t size() const { return size_; } 50 | T & operator*() const { return *ptr_; } 51 | T * operator->() const { return ptr_; } 52 | T * get() const { return ptr_; } 53 | T & operator[](size_t i) const { return ptr_[i]; } 54 | }; 55 | 56 | template class scoped_array { 57 | private: 58 | T * ptr_; 59 | scoped_array(scoped_array const &); 60 | scoped_array & operator=(scoped_array const &); 61 | typedef scoped_array this_type; 62 | 63 | public: 64 | typedef T element_type; 65 | explicit scoped_array(T * p = 0): ptr_(p) {} 66 | virtual ~scoped_array() { delete [] ptr_; } 67 | void reset(T * p = 0) { 68 | delete [] ptr_; 69 | ptr_ = p; 70 | } 71 | T & operator*() const { return *ptr_; } 72 | T * operator->() const { return ptr_; } 73 | T * get() const { return ptr_; } 74 | T & operator[](size_t i) const { return ptr_[i]; } 75 | }; 76 | 77 | class scoped_string: public scoped_array { 78 | public: 79 | explicit scoped_string() { reset_string(""); } 80 | explicit scoped_string(const std::string &str) { 81 | reset_string(str); 82 | } 83 | 84 | void reset_string(const std::string &str) { 85 | char *p = new char[str.size() + 1]; 86 | strcpy(p, str.c_str()); 87 | reset(p); 88 | } 89 | 90 | void reset_string(const char *str) { 91 | char *p = new char[strlen(str) + 1]; 92 | strcpy(p, str); 93 | reset(p); 94 | } 95 | }; 96 | } 97 | #endif 98 | -------------------------------------------------------------------------------- /doxygen/namespacemembers_func.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | CRF++: Namespace Members 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
CRF++ 26 | 27 |
28 | 29 |
36 |
37 | 38 | 39 | 47 | 53 | 59 |
60 |
61 |  
    62 |
  • createModel() 63 | : CRFPP 64 |
  • 65 |
  • createModelFromArray() 66 | : CRFPP 67 |
  • 68 |
  • createTagger() 69 | : CRFPP 70 |
  • 71 |
  • getLastError() 72 | : CRFPP 73 |
  • 74 |
  • getTaggerError() 75 | : CRFPP 76 |
  • 77 |
78 |
79 | 80 | 81 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /doxygen/namespacemembers.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | CRF++: Namespace Members 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
CRF++ 26 | 27 |
28 | 29 |
36 |
37 | 38 | 39 | 47 | 53 | 59 |
60 |
61 |
Here is a list of all namespace members with links to the namespace documentation for each member:
    62 |
  • createModel() 63 | : CRFPP 64 |
  • 65 |
  • createModelFromArray() 66 | : CRFPP 67 |
  • 68 |
  • createTagger() 69 | : CRFPP 70 |
  • 71 |
  • getLastError() 72 | : CRFPP 73 |
  • 74 |
  • getTaggerError() 75 | : CRFPP 76 |
  • 77 |
78 |
79 | 80 | 81 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.in by autoheader. */ 2 | 3 | /* Define to 1 if you have the header file. */ 4 | #undef HAVE_CTYPE_H 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #undef HAVE_DLFCN_H 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #undef HAVE_FCNTL_H 11 | 12 | /* Define to 1 if you have the `getpagesize' function. */ 13 | #undef HAVE_GETPAGESIZE 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_INTTYPES_H 17 | 18 | /* Define to 1 if you have the `m' library (-lm). */ 19 | #undef HAVE_LIBM 20 | 21 | /* Define to 1 if you have the `pthread' library (-lpthread). */ 22 | #undef HAVE_LIBPTHREAD 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_MATH_H 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_MEMORY_H 29 | 30 | /* Define to 1 if you have a working `mmap' system call. */ 31 | #undef HAVE_MMAP 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #undef HAVE_PTHREAD_H 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #undef HAVE_STDINT_H 38 | 39 | /* Define to 1 if you have the header file. */ 40 | #undef HAVE_STDLIB_H 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_STRINGS_H 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #undef HAVE_STRING_H 47 | 48 | /* */ 49 | #undef HAVE_SYS_CONF_SC_NPROCESSORS_CONF 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #undef HAVE_SYS_MMAN_H 53 | 54 | /* Define to 1 if you have the header file. */ 55 | #undef HAVE_SYS_PARAM_H 56 | 57 | /* Define to 1 if you have the header file. */ 58 | #undef HAVE_SYS_STAT_H 59 | 60 | /* Define to 1 if you have the header file. */ 61 | #undef HAVE_SYS_TIMES_H 62 | 63 | /* Define to 1 if you have the header file. */ 64 | #undef HAVE_SYS_TYPES_H 65 | 66 | /* */ 67 | #undef HAVE_TLS_KEYWORD 68 | 69 | /* Define to 1 if you have the header file. */ 70 | #undef HAVE_UNISTD_H 71 | 72 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 73 | */ 74 | #undef LT_OBJDIR 75 | 76 | /* Name of package */ 77 | #undef PACKAGE 78 | 79 | /* Define to the address where bug reports for this package should be sent. */ 80 | #undef PACKAGE_BUGREPORT 81 | 82 | /* Define to the full name of this package. */ 83 | #undef PACKAGE_NAME 84 | 85 | /* Define to the full name and version of this package. */ 86 | #undef PACKAGE_STRING 87 | 88 | /* Define to the one symbol short name of this package. */ 89 | #undef PACKAGE_TARNAME 90 | 91 | /* Define to the home page for this package. */ 92 | #undef PACKAGE_URL 93 | 94 | /* Define to the version of this package. */ 95 | #undef PACKAGE_VERSION 96 | 97 | /* Define to 1 if you have the ANSI C header files. */ 98 | #undef STDC_HEADERS 99 | 100 | /* Version number of package */ 101 | #undef VERSION 102 | 103 | /* Define to `unsigned int' if does not define. */ 104 | #undef size_t 105 | -------------------------------------------------------------------------------- /doxygen/classes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | CRF++: Class Index 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
CRF++ 26 | 27 |
28 | 29 |
36 |
37 | 38 | 39 | 47 | 53 |
54 |
55 |
56 |
Class Index
57 |
58 |
59 |
M | T
60 | 61 | 64 | 65 | 66 | 67 |
  M  
62 |
  T  
63 |
Model (CRFPP)   Tagger (CRFPP)   
68 |
M | T
69 |
70 | 71 | 72 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.in by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #define HAVE_CTYPE_H 1 6 | 7 | /* Define to 1 if you have the header file. */ 8 | #define HAVE_DLFCN_H 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_FCNTL_H 1 12 | 13 | /* Define to 1 if you have the `getpagesize' function. */ 14 | #define HAVE_GETPAGESIZE 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_INTTYPES_H 1 18 | 19 | /* Define to 1 if you have the `m' library (-lm). */ 20 | #define HAVE_LIBM 1 21 | 22 | /* Define to 1 if you have the `pthread' library (-lpthread). */ 23 | #define HAVE_LIBPTHREAD 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_MATH_H 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #define HAVE_MEMORY_H 1 30 | 31 | /* Define to 1 if you have a working `mmap' system call. */ 32 | #define HAVE_MMAP 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_PTHREAD_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #define HAVE_STDINT_H 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_STDLIB_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_STRINGS_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_STRING_H 1 48 | 49 | /* */ 50 | #define HAVE_SYS_CONF_SC_NPROCESSORS_CONF 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_SYS_MMAN_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #define HAVE_SYS_PARAM_H 1 57 | 58 | /* Define to 1 if you have the header file. */ 59 | #define HAVE_SYS_STAT_H 1 60 | 61 | /* Define to 1 if you have the header file. */ 62 | #define HAVE_SYS_TIMES_H 1 63 | 64 | /* Define to 1 if you have the header file. */ 65 | #define HAVE_SYS_TYPES_H 1 66 | 67 | /* */ 68 | #define HAVE_TLS_KEYWORD 1 69 | 70 | /* Define to 1 if you have the header file. */ 71 | #define HAVE_UNISTD_H 1 72 | 73 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 74 | */ 75 | #define LT_OBJDIR ".libs/" 76 | 77 | /* Name of package */ 78 | #define PACKAGE "CRF++" 79 | 80 | /* Define to the address where bug reports for this package should be sent. */ 81 | #define PACKAGE_BUGREPORT "" 82 | 83 | /* Define to the full name of this package. */ 84 | #define PACKAGE_NAME "" 85 | 86 | /* Define to the full name and version of this package. */ 87 | #define PACKAGE_STRING "" 88 | 89 | /* Define to the one symbol short name of this package. */ 90 | #define PACKAGE_TARNAME "" 91 | 92 | /* Define to the home page for this package. */ 93 | #define PACKAGE_URL "" 94 | 95 | /* Define to the version of this package. */ 96 | #define PACKAGE_VERSION "" 97 | 98 | /* Define to 1 if you have the ANSI C header files. */ 99 | /* #undef STDC_HEADERS */ 100 | 101 | /* Version number of package */ 102 | #define VERSION "0.59" 103 | 104 | /* Define to `unsigned int' if does not define. */ 105 | /* #undef size_t */ 106 | -------------------------------------------------------------------------------- /merge-models.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | use strict; 4 | use warnings; 5 | my %model_u; 6 | my %model_b; 7 | my $xsize = -1; 8 | my $version = -1; 9 | my $cost_factor = -1; 10 | my $template = ""; 11 | my @class = (); 12 | my $model_size = 0; 13 | 14 | die "merge-models.pl files ... > new_text_file\n" if (scalar(@ARGV) == 0); 15 | 16 | for my $file (@ARGV) { 17 | print STDERR "reading $file ..\n"; 18 | 19 | # header 20 | open(F, $file) || die "$file\n"; 21 | while () { 22 | chomp; 23 | last if (/^$/); 24 | if (/xsize: (\S+)/) { 25 | die "xsize $xsize != $1\n" if ($xsize != -1 && $xsize != $1); 26 | $xsize = $1; 27 | } elsif (/version: (\S+)/) { 28 | die "version $version != $1\n" if ($version != -1 && $version != $1); 29 | $version = $1; 30 | } elsif (/cost-factor: (\S+)/) { 31 | die "cost-factor $cost_factor != $1\n" if ($cost_factor != -1 && $cost_factor != $1); 32 | $cost_factor = $1; 33 | } 34 | } 35 | 36 | # class 37 | my @tmp = (); 38 | while () { 39 | chomp; 40 | last if (/^$/); 41 | push @tmp, $_; 42 | } 43 | 44 | die "@tmp != @class\n" if (@class && join(" ", @tmp) ne join(" ", @class)); 45 | @class = @tmp; 46 | 47 | # template 48 | my $templ = ""; 49 | while () { 50 | last if (/^$/); 51 | $templ .= $_; 52 | } 53 | 54 | die "$templ != $template\n" if ($template ne "" && $template ne $templ); 55 | $template = $templ; 56 | 57 | # dic 58 | my %u; 59 | my %b; 60 | while () { 61 | chomp; 62 | last if (/^$/); 63 | my ($id, $v) = split; 64 | if ($v =~ /^U/) { 65 | $u{$v} = $id; 66 | } elsif ($v =~ /^B/) { 67 | $b{$v} = $id; 68 | } 69 | } 70 | 71 | # weights 72 | my @w; 73 | while () { 74 | chomp; 75 | push @w, $_; 76 | } 77 | close(F); 78 | 79 | ## merge 80 | { 81 | my $size = scalar(@class); 82 | for my $v (keys %u) { 83 | my $id = $u{$v}; 84 | for (my $i = 0; $i < $size; ++$i) { 85 | $model_u{$v}->[$i] += $w[$id + $i]; 86 | } 87 | } 88 | } 89 | 90 | { 91 | my $size = scalar(@class) * scalar(@class); 92 | for my $v (keys %b) { 93 | my $id = $b{$v}; 94 | for (my $i = 0; $i < $size; ++$i) { 95 | $model_b{$v}->[$i] += $w[$id + $i]; 96 | } 97 | } 98 | } 99 | 100 | ++$model_size; 101 | } 102 | 103 | my $size = scalar(@class); 104 | my $maxid = scalar(keys %model_u) * $size + scalar(keys %model_b) * $size * $size; 105 | 106 | # output 107 | print "version: $version\n"; 108 | print "cost-factor: 1\n"; 109 | print "maxid: $maxid\n"; 110 | print "xsize: $xsize\n"; 111 | print "\n"; 112 | print (join "\n", @class); 113 | print "\n\n"; 114 | print $template; 115 | print "\n"; 116 | 117 | my $id = 0; 118 | my @w; 119 | for my $v (sort keys %model_b) { 120 | my $size = scalar(@class) * scalar(@class); 121 | for (my $i = 0; $i < $size; ++$i) { 122 | push @w, 1.0 * $model_b{$v}->[$i] / $model_size; 123 | } 124 | print "$id $v\n"; 125 | $id += $size; 126 | } 127 | 128 | for my $v (sort keys %model_u) { 129 | my $size = scalar(@class); 130 | for (my $i = 0; $i < $size; ++$i) { 131 | push @w, 1.0 * $model_u{$v}->[$i] / $model_size; 132 | } 133 | print "$id $v\n"; 134 | $id += $size; 135 | } 136 | 137 | print "\n"; 138 | 139 | for (@w) { 140 | print "$_\n"; 141 | } 142 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = README Makefile.msvc.in merge-models.pl 2 | EXTRA_DIRS = doc example sdk perl python ruby java swig 3 | bin_PROGRAMS = crf_learn crf_test 4 | ACLOCAL_AMFLAGS = -I m4 5 | 6 | AUTOMAKE_OPTIONS = no-dependencies 7 | lib_LTLIBRARIES = libcrfpp.la 8 | libcrfpp_la_SOURCES = crfpp.h thread.h libcrfpp.cpp lbfgs.cpp scoped_ptr.h param.cpp param.h encoder.cpp feature.cpp stream_wrapper.h \ 9 | feature_cache.cpp feature_index.cpp node.cpp path.cpp tagger.cpp \ 10 | common.h darts.h encoder.h feature_cache.h feature_index.h \ 11 | freelist.h lbfgs.h mmap.h node.h path.h tagger.h timer.h winmain.h 12 | include_HEADERS = crfpp.h 13 | 14 | dist-hook: 15 | for subdir in $(EXTRA_DIRS); do \ 16 | cp -rp $$subdir $(distdir); \ 17 | rm -f $(distdir)/$$subdir/*~; \ 18 | rm -f $(distdir)/$$subdir/*.{bak,orig}; \ 19 | rm -rf $(distdir)/$$subdir/CVS; \ 20 | rm -rf $(distdir)/$$subdir/.svn; \ 21 | rm -rf $(distdir)/.svn; \ 22 | rm -rf $(distdir)/*/.svn; \ 23 | rm -rf $(distdir)/*/*/.svn; \ 24 | rm -rf $(distdir)/$$subdir/*/CVS; \ 25 | rm -rf $(distdir)/$$subdir/*/.svn; \ 26 | find $(distdir) -name .svn | xargs rm -fr; \ 27 | done 28 | 29 | win-dist: 30 | rm -f @PACKAGE@-@VERSION@.zip 31 | mkdir -p @PACKAGE@-@VERSION@/doc 32 | mkdir -p @PACKAGE@-@VERSION@/example 33 | mkdir -p @PACKAGE@-@VERSION@/sdk 34 | cp -f crf_learn.exe @PACKAGE@-@VERSION@ 35 | cp -f crf_test.exe @PACKAGE@-@VERSION@ 36 | cp -f libcrfpp.dll @PACKAGE@-@VERSION@ 37 | cp -f libcrfpp.lib @PACKAGE@-@VERSION@/sdk 38 | cp -f crfpp.h @PACKAGE@-@VERSION@/sdk 39 | # cp -f sdk/model @PACKAGE@-@VERSION@/sdk 40 | cp -f sdk/example.cpp @PACKAGE@-@VERSION@/sdk 41 | cp -fr doc/*.html doc/*.css doc/doxygen @PACKAGE@-@VERSION@/doc 42 | cp -f README COPYING AUTHORS LGPL BSD @PACKAGE@-@VERSION@ 43 | cp -fr example/* @PACKAGE@-@VERSION@/example 44 | find @PACKAGE@-@VERSION@ -name CVS | xargs rm -rf 45 | find @PACKAGE@-@VERSION@ -name .svn | xargs rm -rf 46 | zip -r @PACKAGE@-@VERSION@.zip @PACKAGE@-@VERSION@ 47 | rm -fr @PACKAGE@-@VERSION@ 48 | 49 | crf_learn_SOURCES = crf_learn.cpp 50 | crf_learn_LDADD = libcrfpp.la 51 | 52 | crf_test_SOURCES = crf_test.cpp 53 | crf_test_LDADD = libcrfpp.la 54 | 55 | dist-all-package: 56 | (test -f Makefile) && $(MAKE) distclean 57 | ./configure 58 | $(MAKE) dist 59 | $(MAKE) clean 60 | $(MAKE) script-clean 61 | $(MAKE) script-dist 62 | $(MAKE) win-dist 63 | 64 | script-dist: 65 | for subdir in perl ruby python java; do \ 66 | rm -fr CRF++-$${subdir}-@VERSION@; \ 67 | mkdir CRF++-$${subdir}-@VERSION@; \ 68 | cp -r $${subdir}/* CRF++-$${subdir}-@VERSION@; \ 69 | cp -r doc/bindings.html CRF++-$${subdir}-@VERSION@; \ 70 | find ./CRF++-$${subdir}-@VERSION@ -type d -name CVS | xargs rm -fr; \ 71 | rm -f CRF++-$${subdir}-@VERSION@/*~; \ 72 | tar zcfv CRF++-$${subdir}-@VERSION@.tar.gz CRF++-$${subdir}-@VERSION@; \ 73 | rm -fr CRF++-$${subdir}-@VERSION@; \ 74 | done 75 | 76 | script-clean: 77 | (cd perl; $(MAKE) clean; rm -f Makefile.old Makefile) 78 | (cd ruby; $(MAKE) clean; rm -f Makefile *.log) 79 | (cd python; python setup.py clean --all) 80 | (cd java; $(MAKE) clean;) 81 | 82 | export-package: 83 | python googlecode_upload.py -p crfpp -s crfpp -u taku@chasen.org -w `cat ~/.googlecode_upload_password` CRF++-@VERSION@.tar.gz 84 | python googlecode_upload.py -p crfpp -s crfpp-win -u taku@chasen.org -w `cat ~/.googlecode_upload_password` CRF++-@VERSION@.zip 85 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | [ -f configure.in ] || { 4 | echo "autogen.sh: run this command only at the top of the source tree." 5 | exit 1 6 | } 7 | 8 | DIE=0 9 | 10 | (autoconf --version) < /dev/null > /dev/null 2>&1 || { 11 | echo 12 | echo "You must have autoconf installed." 13 | echo "Get ftp://ftp.gnu.org/pub/gnu/autoconf/autoconf-2.13.tar.gz" 14 | echo "(or a newer version if it is available)" 15 | DIE=1 16 | NO_AUTOCONF=yes 17 | } 18 | 19 | (automake --version) < /dev/null > /dev/null 2>&1 || { 20 | echo 21 | echo "You must have automake installed." 22 | echo "Get ftp://ftp.gnu.org/pub/gnu/automake/automake-1.4.tar.gz" 23 | echo "(or a newer version if it is available)" 24 | DIE=1 25 | NO_AUTOMAKE=yes 26 | } 27 | 28 | # if no automake, don't bother testing for aclocal 29 | test -n "$NO_AUTOMAKE" || (aclocal --version) < /dev/null > /dev/null 2>&1 || { 30 | echo 31 | echo "**Error**: Missing \`aclocal'. The version of \`automake'" 32 | echo "installed doesn't appear recent enough." 33 | echo "Get ftp://ftp.gnu.org/pub/gnu/automake/automake-1.4.tar.gz" 34 | echo "(or a newer version if it is available)" 35 | DIE=1 36 | } 37 | 38 | # if no autoconf, don't bother testing for autoheader 39 | test -n "$NO_AUTOCONF" || (autoheader --version) < /dev/null > /dev/null 2>&1 || { 40 | echo 41 | echo "**Error**: Missing \`autoheader'. The version of \`autoheader'" 42 | echo "installed doesn't appear recent enough." 43 | echo "Get ftp://ftp.gnu.org/pub/gnu/autoconf/autoconf-2.13.tar.gz" 44 | echo "(or a newer version if it is available)" 45 | DIE=1 46 | } 47 | 48 | grep "^AM_PROG_LIBTOOL" configure.in >/dev/null && { 49 | (libtool --version) < /dev/null > /dev/null 2>&1 || { 50 | echo 51 | echo "**Error**: You must have \`libtool' installed." 52 | echo "Get ftp://ftp.gnu.org/pub/gnu/libtool-1.3.tar.gz" 53 | echo "(or a newer version if it is available)" 54 | DIE=1 55 | } 56 | } 57 | 58 | grep "^AM_GNU_GETTEXT" configure.in >/dev/null && { 59 | grep "sed.*POTFILES" configure.in >/dev/null || \ 60 | (gettext --version) < /dev/null > /dev/null 2>&1 || { 61 | echo 62 | echo "**Error**: You must have \`gettext' installed." 63 | echo "Get ftp://ftp.gnu.org/pub/gnu/gettext-0.10.35.tar.gz" 64 | echo "(or a newer version if it is available)" 65 | DIE=1 66 | } 67 | } 68 | 69 | if test "$DIE" -eq 1; then 70 | exit 1 71 | fi 72 | 73 | if test -z "$*"; then 74 | echo "**Warning**: I am going to run \`configure' with no arguments." 75 | echo "If you wish to pass any to it, please specify them on the" 76 | echo \`$0\'" command line." 77 | echo 78 | fi 79 | 80 | echo "Generating configure script and Makefiles." 81 | 82 | if grep "^AM_GNU_GETTEXT" configure.in >/dev/null; then 83 | echo "Running gettextize..." 84 | rm -f config.status 85 | gettextize --force --copy 86 | fi 87 | if grep "^AM_PROG_LIBTOOL" configure.in >/dev/null; then 88 | echo "Running libtoolize..." 89 | libtoolize --force --copy 90 | fi 91 | 92 | echo "Running aclocal ..." 93 | aclocal -I . 94 | echo "Running autoheader..." 95 | autoheader 96 | echo "Running automake ..." 97 | automake --add-missing --copy 98 | echo "Running autoconf ..." 99 | autoconf 100 | 101 | echo "Configuring." 102 | conf_flags="--enable-maintainer-mode" 103 | echo Running ./configure $conf_flags "$@" ... 104 | ./configure $conf_flags "$@" 105 | echo "Now type 'make' to compile." 106 | 107 | -------------------------------------------------------------------------------- /lbfgs.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: lbfgs.h 1588 2007-02-12 09:03:39Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_LBFGS_H_ 9 | #define CRFPP_LBFGS_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace CRFPP { 16 | 17 | class LBFGS { 18 | private: 19 | class Mcsrch; 20 | int iflag_, iscn, nfev, iycn, point, npt; 21 | int iter, info, ispt, isyt, iypt, maxfev; 22 | double stp, stp1; 23 | std::vector diag_; 24 | std::vector w_; 25 | std::vector v_; 26 | std::vector xi_; 27 | Mcsrch *mcsrch_; 28 | 29 | void pseudo_gradient(int size, 30 | double *v, 31 | double *x, 32 | const double *g, 33 | double C); 34 | 35 | void lbfgs_optimize(int size, 36 | int msize, 37 | double *x, 38 | double f, 39 | const double *g, 40 | double *diag, 41 | double *w, bool orthant, 42 | double C, double *v, double *xi, int *iflag); 43 | 44 | public: 45 | explicit LBFGS(): iflag_(0), iscn(0), nfev(0), iycn(0), 46 | point(0), npt(0), iter(0), info(0), 47 | ispt(0), isyt(0), iypt(0), maxfev(0), 48 | stp(0.0), stp1(0.0), mcsrch_(0) {} 49 | virtual ~LBFGS() { clear(); } 50 | 51 | void clear(); 52 | 53 | // This is old interface for backward compatibility 54 | // ignore msize |m| 55 | int init(int n, int m) { 56 | static const int msize = 5; 57 | const size_t size = n; 58 | iflag_ = 0; 59 | w_.resize(size * (2 * msize + 1) + 2 * msize); 60 | diag_.resize(size); 61 | v_.resize(size); 62 | return 0; 63 | } 64 | 65 | // old interface 66 | int optimize(double *x, double *f, double *g) { 67 | return optimize(diag_.size(), x, *f, g, false, 1.0); 68 | } 69 | 70 | // Use this interface 71 | int optimize(size_t size, double *x, double f, 72 | double *g, bool orthant, double C) { 73 | static const int msize = 5; 74 | if (w_.empty()) { 75 | iflag_ = 0; 76 | w_.resize(size * (2 * msize + 1) + 2 * msize); 77 | diag_.resize(size); 78 | v_.resize(size); 79 | if (orthant) { 80 | xi_.resize(size); 81 | } 82 | } else if (diag_.size() != size || v_.size() != size) { 83 | std::cerr << "size of array is different" << std::endl; 84 | return -1; 85 | } else if (orthant && v_.size() != size) { 86 | std::cerr << "size of array is different" << std::endl; 87 | return -1; 88 | } 89 | 90 | if (orthant) { 91 | lbfgs_optimize(static_cast(size), 92 | msize, x, f, g, &diag_[0], &w_[0], orthant, 93 | C, &v_[0], &xi_[0], &iflag_); 94 | } else { 95 | lbfgs_optimize(static_cast(size), 96 | msize, x, f, g, &diag_[0], &w_[0], orthant, 97 | C, g, &xi_[0], &iflag_); 98 | } 99 | 100 | if (iflag_ < 0) { 101 | std::cerr << "routine stops with unexpected error" << std::endl; 102 | return -1; 103 | } 104 | 105 | if (iflag_ == 0) { 106 | clear(); 107 | return 0; // terminate 108 | } 109 | 110 | return 1; // evaluate next f and g 111 | } 112 | }; 113 | } 114 | #endif 115 | -------------------------------------------------------------------------------- /feature_index.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: feature_index.h 1588 2007-02-12 09:03:39Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_FEATURE_INDEX_H_ 9 | #define CRFPP_FEATURE_INDEX_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "common.h" 15 | #include "scoped_ptr.h" 16 | #include "feature_cache.h" 17 | #include "path.h" 18 | #include "node.h" 19 | #include "freelist.h" 20 | #include "mmap.h" 21 | #include "darts.h" 22 | 23 | namespace CRFPP { 24 | class TaggerImpl; 25 | 26 | class Allocator { 27 | public: 28 | explicit Allocator(size_t thread_num); 29 | Allocator(); 30 | virtual ~Allocator(); 31 | 32 | char *strdup(const char *str); 33 | Path *newPath(size_t thread_id); 34 | Node *newNode(size_t thread_id); 35 | void clear(); 36 | void clear_freelist(size_t thread_id); 37 | FeatureCache *feature_cache() const; 38 | size_t thread_num() const; 39 | 40 | private: 41 | void init(); 42 | 43 | size_t thread_num_; 44 | scoped_ptr feature_cache_; 45 | scoped_ptr > char_freelist_; 46 | scoped_array< FreeList > path_freelist_; 47 | scoped_array< FreeList > node_freelist_; 48 | }; 49 | 50 | class FeatureIndex { 51 | public: 52 | static const unsigned int version = MODEL_VERSION; 53 | 54 | size_t size() const { return maxid_; } 55 | size_t xsize() const { return xsize_; } 56 | size_t ysize() const { return y_.size(); } 57 | const char* y(size_t i) const { return y_[i].c_str(); } 58 | void set_alpha(const double *alpha) { alpha_ = alpha; } 59 | const float *alpha_float() { return alpha_float_; } 60 | const double *alpha() const { return alpha_; } 61 | void set_cost_factor(double cost_factor) { cost_factor_ = cost_factor; } 62 | double cost_factor() const { return cost_factor_; } 63 | 64 | void calcCost(Node *node) const; 65 | void calcCost(Path *path) const; 66 | 67 | bool buildFeatures(TaggerImpl *tagger) const; 68 | void rebuildFeatures(TaggerImpl *tagger) const; 69 | 70 | const char* what() { return what_.str(); } 71 | 72 | explicit FeatureIndex(): maxid_(0), alpha_(0), alpha_float_(0), 73 | cost_factor_(1.0), xsize_(0), 74 | check_max_xsize_(false), max_xsize_(0) {} 75 | virtual ~FeatureIndex() {} 76 | 77 | const char *getTemplate() const; 78 | 79 | protected: 80 | virtual int getID(const char *str) const = 0; 81 | const char *getIndex(const char *&p, 82 | size_t pos, 83 | const TaggerImpl &tagger) const; 84 | bool applyRule(string_buffer *os, 85 | const char *pattern, 86 | size_t pos, const TaggerImpl &tagger) const; 87 | 88 | mutable unsigned int maxid_; 89 | const double *alpha_; 90 | const float *alpha_float_; 91 | double cost_factor_; 92 | unsigned int xsize_; 93 | bool check_max_xsize_; 94 | mutable unsigned int max_xsize_; 95 | std::vector unigram_templs_; 96 | std::vector bigram_templs_; 97 | std::vector y_; 98 | std::string templs_; 99 | whatlog what_; 100 | }; 101 | 102 | class EncoderFeatureIndex: public FeatureIndex { 103 | public: 104 | bool open(const char *template_filename, 105 | const char *model_filename); 106 | bool save(const char *filename, bool emit_textmodelfile); 107 | bool convert(const char *text_filename, 108 | const char *binary_filename); 109 | void shrink(size_t freq, Allocator *allocator); 110 | 111 | private: 112 | int getID(const char *str) const; 113 | bool openTemplate(const char *filename); 114 | bool openTagSet(const char *filename); 115 | mutable std::map > dic_; 116 | }; 117 | 118 | class DecoderFeatureIndex: public FeatureIndex { 119 | public: 120 | bool open(const char *model_filename); 121 | bool openFromArray(const char *buf, size_t size); 122 | 123 | private: 124 | Mmap mmap_; 125 | Darts::DoubleArray da_; 126 | int getID(const char *str) const; 127 | }; 128 | } 129 | #endif 130 | -------------------------------------------------------------------------------- /java/org/chasen/crfpp/CRFPPJNI.java: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 2.0.4 4 | * 5 | * Do not make changes to this file unless you know what you are doing--modify 6 | * the SWIG interface file instead. 7 | * ----------------------------------------------------------------------------- */ 8 | 9 | package org.chasen.crfpp; 10 | 11 | public class CRFPPJNI { 12 | public final static native String Model_getTemplate(long jarg1, Model jarg1_); 13 | public final static native long Model_createTagger(long jarg1, Model jarg1_); 14 | public final static native String Model_what(long jarg1, Model jarg1_); 15 | public final static native void delete_Model(long jarg1); 16 | public final static native long new_Model(String jarg1); 17 | public final static native boolean Tagger_set_model(long jarg1, Tagger jarg1_, long jarg2, Model jarg2_); 18 | public final static native void Tagger_set_vlevel(long jarg1, Tagger jarg1_, long jarg2); 19 | public final static native long Tagger_vlevel(long jarg1, Tagger jarg1_); 20 | public final static native void Tagger_set_cost_factor(long jarg1, Tagger jarg1_, float jarg2); 21 | public final static native float Tagger_cost_factor(long jarg1, Tagger jarg1_); 22 | public final static native void Tagger_set_nbest(long jarg1, Tagger jarg1_, long jarg2); 23 | public final static native long Tagger_nbest(long jarg1, Tagger jarg1_); 24 | public final static native boolean Tagger_add(long jarg1, Tagger jarg1_, String jarg2); 25 | public final static native long Tagger_size(long jarg1, Tagger jarg1_); 26 | public final static native long Tagger_xsize(long jarg1, Tagger jarg1_); 27 | public final static native long Tagger_dsize(long jarg1, Tagger jarg1_); 28 | public final static native long Tagger_result(long jarg1, Tagger jarg1_, long jarg2); 29 | public final static native long Tagger_answer(long jarg1, Tagger jarg1_, long jarg2); 30 | public final static native long Tagger_y(long jarg1, Tagger jarg1_, long jarg2); 31 | public final static native String Tagger_y2(long jarg1, Tagger jarg1_, long jarg2); 32 | public final static native String Tagger_yname(long jarg1, Tagger jarg1_, long jarg2); 33 | public final static native String Tagger_x(long jarg1, Tagger jarg1_, long jarg2, long jarg3); 34 | public final static native long Tagger_ysize(long jarg1, Tagger jarg1_); 35 | public final static native double Tagger_prob__SWIG_0(long jarg1, Tagger jarg1_, long jarg2, long jarg3); 36 | public final static native double Tagger_prob__SWIG_1(long jarg1, Tagger jarg1_, long jarg2); 37 | public final static native double Tagger_prob__SWIG_2(long jarg1, Tagger jarg1_); 38 | public final static native void Tagger_set_penalty(long jarg1, Tagger jarg1_, long jarg2, long jarg3, double jarg4); 39 | public final static native double Tagger_penalty(long jarg1, Tagger jarg1_, long jarg2, long jarg3); 40 | public final static native double Tagger_alpha(long jarg1, Tagger jarg1_, long jarg2, long jarg3); 41 | public final static native double Tagger_beta(long jarg1, Tagger jarg1_, long jarg2, long jarg3); 42 | public final static native double Tagger_emission_cost(long jarg1, Tagger jarg1_, long jarg2, long jarg3); 43 | public final static native double Tagger_next_transition_cost(long jarg1, Tagger jarg1_, long jarg2, long jarg3, long jarg4); 44 | public final static native double Tagger_prev_transition_cost(long jarg1, Tagger jarg1_, long jarg2, long jarg3, long jarg4); 45 | public final static native double Tagger_best_cost(long jarg1, Tagger jarg1_, long jarg2, long jarg3); 46 | public final static native double Tagger_Z(long jarg1, Tagger jarg1_); 47 | public final static native boolean Tagger_parse__SWIG_0(long jarg1, Tagger jarg1_); 48 | public final static native boolean Tagger_empty(long jarg1, Tagger jarg1_); 49 | public final static native boolean Tagger_clear(long jarg1, Tagger jarg1_); 50 | public final static native boolean Tagger_next(long jarg1, Tagger jarg1_); 51 | public final static native String Tagger_parse__SWIG_1(long jarg1, Tagger jarg1_, String jarg2); 52 | public final static native String Tagger_what(long jarg1, Tagger jarg1_); 53 | public final static native void delete_Tagger(long jarg1); 54 | public final static native long new_Tagger(String jarg1); 55 | public final static native String VERSION_get(); 56 | } 57 | -------------------------------------------------------------------------------- /perl/CRFPP.pm: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by SWIG (http://www.swig.org). 2 | # Version 2.0.4 3 | # 4 | # Do not make changes to this file unless you know what you are doing--modify 5 | # the SWIG interface file instead. 6 | 7 | package CRFPP; 8 | use base qw(Exporter); 9 | use base qw(DynaLoader); 10 | package CRFPPc; 11 | bootstrap CRFPP; 12 | package CRFPP; 13 | @EXPORT = qw(); 14 | 15 | # ---------- BASE METHODS ------------- 16 | 17 | package CRFPP; 18 | 19 | sub TIEHASH { 20 | my ($classname,$obj) = @_; 21 | return bless $obj, $classname; 22 | } 23 | 24 | sub CLEAR { } 25 | 26 | sub FIRSTKEY { } 27 | 28 | sub NEXTKEY { } 29 | 30 | sub FETCH { 31 | my ($self,$field) = @_; 32 | my $member_func = "swig_${field}_get"; 33 | $self->$member_func(); 34 | } 35 | 36 | sub STORE { 37 | my ($self,$field,$newval) = @_; 38 | my $member_func = "swig_${field}_set"; 39 | $self->$member_func($newval); 40 | } 41 | 42 | sub this { 43 | my $ptr = shift; 44 | return tied(%$ptr); 45 | } 46 | 47 | 48 | # ------- FUNCTION WRAPPERS -------- 49 | 50 | package CRFPP; 51 | 52 | 53 | ############# Class : CRFPP::Model ############## 54 | 55 | package CRFPP::Model; 56 | use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); 57 | @ISA = qw( CRFPP ); 58 | %OWNER = (); 59 | %ITERATORS = (); 60 | *getTemplate = *CRFPPc::Model_getTemplate; 61 | *createTagger = *CRFPPc::Model_createTagger; 62 | *what = *CRFPPc::Model_what; 63 | sub DESTROY { 64 | return unless $_[0]->isa('HASH'); 65 | my $self = tied(%{$_[0]}); 66 | return unless defined $self; 67 | delete $ITERATORS{$self}; 68 | if (exists $OWNER{$self}) { 69 | CRFPPc::delete_Model($self); 70 | delete $OWNER{$self}; 71 | } 72 | } 73 | 74 | sub new { 75 | my $pkg = shift; 76 | my $self = CRFPPc::new_Model(@_); 77 | bless $self, $pkg if defined($self); 78 | } 79 | 80 | sub DISOWN { 81 | my $self = shift; 82 | my $ptr = tied(%$self); 83 | delete $OWNER{$ptr}; 84 | } 85 | 86 | sub ACQUIRE { 87 | my $self = shift; 88 | my $ptr = tied(%$self); 89 | $OWNER{$ptr} = 1; 90 | } 91 | 92 | 93 | ############# Class : CRFPP::Tagger ############## 94 | 95 | package CRFPP::Tagger; 96 | use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); 97 | @ISA = qw( CRFPP ); 98 | %OWNER = (); 99 | %ITERATORS = (); 100 | *set_model = *CRFPPc::Tagger_set_model; 101 | *set_vlevel = *CRFPPc::Tagger_set_vlevel; 102 | *vlevel = *CRFPPc::Tagger_vlevel; 103 | *set_cost_factor = *CRFPPc::Tagger_set_cost_factor; 104 | *cost_factor = *CRFPPc::Tagger_cost_factor; 105 | *set_nbest = *CRFPPc::Tagger_set_nbest; 106 | *nbest = *CRFPPc::Tagger_nbest; 107 | *add = *CRFPPc::Tagger_add; 108 | *size = *CRFPPc::Tagger_size; 109 | *xsize = *CRFPPc::Tagger_xsize; 110 | *dsize = *CRFPPc::Tagger_dsize; 111 | *result = *CRFPPc::Tagger_result; 112 | *answer = *CRFPPc::Tagger_answer; 113 | *y = *CRFPPc::Tagger_y; 114 | *y2 = *CRFPPc::Tagger_y2; 115 | *yname = *CRFPPc::Tagger_yname; 116 | *x = *CRFPPc::Tagger_x; 117 | *ysize = *CRFPPc::Tagger_ysize; 118 | *prob = *CRFPPc::Tagger_prob; 119 | *set_penalty = *CRFPPc::Tagger_set_penalty; 120 | *penalty = *CRFPPc::Tagger_penalty; 121 | *alpha = *CRFPPc::Tagger_alpha; 122 | *beta = *CRFPPc::Tagger_beta; 123 | *emission_cost = *CRFPPc::Tagger_emission_cost; 124 | *next_transition_cost = *CRFPPc::Tagger_next_transition_cost; 125 | *prev_transition_cost = *CRFPPc::Tagger_prev_transition_cost; 126 | *best_cost = *CRFPPc::Tagger_best_cost; 127 | *Z = *CRFPPc::Tagger_Z; 128 | *empty = *CRFPPc::Tagger_empty; 129 | *clear = *CRFPPc::Tagger_clear; 130 | *next = *CRFPPc::Tagger_next; 131 | *parse = *CRFPPc::Tagger_parse; 132 | *what = *CRFPPc::Tagger_what; 133 | sub DESTROY { 134 | return unless $_[0]->isa('HASH'); 135 | my $self = tied(%{$_[0]}); 136 | return unless defined $self; 137 | delete $ITERATORS{$self}; 138 | if (exists $OWNER{$self}) { 139 | CRFPPc::delete_Tagger($self); 140 | delete $OWNER{$self}; 141 | } 142 | } 143 | 144 | sub new { 145 | my $pkg = shift; 146 | my $self = CRFPPc::new_Tagger(@_); 147 | bless $self, $pkg if defined($self); 148 | } 149 | 150 | sub DISOWN { 151 | my $self = shift; 152 | my $ptr = tied(%$self); 153 | delete $OWNER{$ptr}; 154 | } 155 | 156 | sub ACQUIRE { 157 | my $self = shift; 158 | my $ptr = tied(%$self); 159 | $OWNER{$ptr} = 1; 160 | } 161 | 162 | 163 | # ------- VARIABLE STUBS -------- 164 | 165 | package CRFPP; 166 | 167 | *VERSION = *CRFPPc::VERSION; 168 | 1; 169 | -------------------------------------------------------------------------------- /doxygen/classCRFPP_1_1Model-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | CRF++: Member List 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
CRF++ 26 | 27 |
28 | 29 |
36 |
37 | 38 | 39 | 47 | 53 | 59 |
60 |
61 |
62 |
CRFPP::Model Member List
63 |
64 |
65 | This is the complete list of members for CRFPP::Model, including all inherited members. 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 |
createTagger() const =0CRFPP::Model [pure virtual]
getTemplate() const =0CRFPP::Model [pure virtual]
open(int argc, char **argv)=0CRFPP::Model [pure virtual]
open(const char *arg)=0CRFPP::Model [pure virtual]
openFromArray(int argc, char **argv, const char *model_buf, size_t model_size)=0CRFPP::Model [pure virtual]
openFromArray(const char *arg, const char *model_buf, size_t model_size)=0CRFPP::Model [pure virtual]
what()=0CRFPP::Model [pure virtual]
~Model()CRFPP::Model [inline, virtual]
75 | 76 | 77 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /ruby/Makefile: -------------------------------------------------------------------------------- 1 | 2 | SHELL = /bin/sh 3 | 4 | #### Start of system configuration section. #### 5 | 6 | srcdir = . 7 | topdir = /usr/lib/ruby/1.8/x86_64-linux 8 | hdrdir = $(topdir) 9 | VPATH = $(srcdir):$(topdir):$(hdrdir) 10 | exec_prefix = $(prefix) 11 | prefix = $(DESTDIR)/usr 12 | sharedstatedir = $(prefix)/com 13 | mandir = $(prefix)/share/man 14 | psdir = $(docdir) 15 | oldincludedir = $(DESTDIR)/usr/include 16 | localedir = $(datarootdir)/locale 17 | bindir = $(exec_prefix)/bin 18 | libexecdir = $(prefix)/lib/ruby1.8 19 | sitedir = $(DESTDIR)/usr/local/lib/site_ruby 20 | htmldir = $(docdir) 21 | vendorarchdir = $(vendorlibdir)/$(sitearch) 22 | includedir = $(prefix)/include 23 | infodir = $(prefix)/share/info 24 | vendorlibdir = $(vendordir)/$(ruby_version) 25 | sysconfdir = $(DESTDIR)/etc 26 | libdir = $(exec_prefix)/lib 27 | sbindir = $(exec_prefix)/sbin 28 | rubylibdir = $(libdir)/ruby/$(ruby_version) 29 | docdir = $(datarootdir)/doc/$(PACKAGE) 30 | dvidir = $(docdir) 31 | vendordir = $(libdir)/ruby/vendor_ruby 32 | datarootdir = $(prefix)/share 33 | pdfdir = $(docdir) 34 | archdir = $(rubylibdir)/$(arch) 35 | sitearchdir = $(sitelibdir)/$(sitearch) 36 | datadir = $(datarootdir) 37 | localstatedir = $(DESTDIR)/var 38 | sitelibdir = $(sitedir)/$(ruby_version) 39 | 40 | CC = gcc 41 | LIBRUBY = $(LIBRUBY_SO) 42 | LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a 43 | LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME) 44 | LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static 45 | 46 | RUBY_EXTCONF_H = 47 | CFLAGS = -fPIC -fno-strict-aliasing -g -g -O2 -fPIC $(cflags) 48 | INCFLAGS = -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. 49 | DEFS = 50 | CPPFLAGS = -DHAVE_CRFPP_H 51 | CXXFLAGS = $(CFLAGS) 52 | ldflags = -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic 53 | dldflags = 54 | archflag = 55 | DLDFLAGS = $(ldflags) $(dldflags) $(archflag) 56 | LDSHARED = $(CC) -shared 57 | AR = ar 58 | EXEEXT = 59 | 60 | RUBY_INSTALL_NAME = ruby1.8 61 | RUBY_SO_NAME = ruby1.8 62 | arch = x86_64-linux 63 | sitearch = x86_64-linux 64 | ruby_version = 1.8 65 | ruby = /usr/bin/ruby1.8 66 | RUBY = $(ruby) 67 | RM = rm -f 68 | MAKEDIRS = mkdir -p 69 | INSTALL = /usr/bin/install -c 70 | INSTALL_PROG = $(INSTALL) -m 0755 71 | INSTALL_DATA = $(INSTALL) -m 644 72 | COPY = cp 73 | 74 | #### End of system configuration section. #### 75 | 76 | preload = 77 | 78 | libpath = . $(libdir) 79 | LIBPATH = -L. -L$(libdir) 80 | DEFFILE = 81 | 82 | CLEANFILES = mkmf.log 83 | DISTCLEANFILES = 84 | 85 | extout = 86 | extout_prefix = 87 | target_prefix = 88 | LOCAL_LIBS = 89 | LIBS = $(LIBRUBYARG_SHARED) -lpthread -lcrfpp -lpthread -lrt -ldl -lcrypt -lm -lc 90 | SRCS = CRFPP_wrap.cpp 91 | OBJS = CRFPP_wrap.o 92 | TARGET = CRFPP 93 | DLLIB = $(TARGET).so 94 | EXTSTATIC = 95 | STATIC_LIB = 96 | 97 | BINDIR = $(bindir) 98 | RUBYCOMMONDIR = $(sitedir)$(target_prefix) 99 | RUBYLIBDIR = $(sitelibdir)$(target_prefix) 100 | RUBYARCHDIR = $(sitearchdir)$(target_prefix) 101 | 102 | TARGET_SO = $(DLLIB) 103 | CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map 104 | CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak 105 | 106 | all: $(DLLIB) 107 | static: $(STATIC_LIB) 108 | 109 | clean: 110 | @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) 111 | 112 | distclean: clean 113 | @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log 114 | @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES) 115 | 116 | realclean: distclean 117 | install: install-so install-rb 118 | 119 | install-so: $(RUBYARCHDIR) 120 | install-so: $(RUBYARCHDIR)/$(DLLIB) 121 | $(RUBYARCHDIR)/$(DLLIB): $(DLLIB) 122 | $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR) 123 | install-rb: pre-install-rb install-rb-default 124 | install-rb-default: pre-install-rb-default 125 | pre-install-rb: Makefile 126 | pre-install-rb-default: Makefile 127 | $(RUBYARCHDIR): 128 | $(MAKEDIRS) $@ 129 | 130 | site-install: site-install-so site-install-rb 131 | site-install-so: install-so 132 | site-install-rb: install-rb 133 | 134 | .SUFFIXES: .c .m .cc .cxx .cpp .C .o 135 | 136 | .cc.o: 137 | $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $< 138 | 139 | .cxx.o: 140 | $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $< 141 | 142 | .cpp.o: 143 | $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $< 144 | 145 | .C.o: 146 | $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $< 147 | 148 | .c.o: 149 | $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $< 150 | 151 | $(DLLIB): $(OBJS) Makefile 152 | @-$(RM) $@ 153 | $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS) 154 | 155 | 156 | 157 | $(OBJS): ruby.h defines.h 158 | -------------------------------------------------------------------------------- /java/org/chasen/crfpp/Tagger.java: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 2.0.4 4 | * 5 | * Do not make changes to this file unless you know what you are doing--modify 6 | * the SWIG interface file instead. 7 | * ----------------------------------------------------------------------------- */ 8 | 9 | package org.chasen.crfpp; 10 | 11 | public class Tagger { 12 | private long swigCPtr; 13 | protected boolean swigCMemOwn; 14 | 15 | public Tagger(long cPtr, boolean cMemoryOwn) { 16 | swigCMemOwn = cMemoryOwn; 17 | swigCPtr = cPtr; 18 | } 19 | 20 | public static long getCPtr(Tagger obj) { 21 | return (obj == null) ? 0 : obj.swigCPtr; 22 | } 23 | 24 | protected void finalize() { 25 | delete(); 26 | } 27 | 28 | public synchronized void delete() { 29 | if (swigCPtr != 0) { 30 | if (swigCMemOwn) { 31 | swigCMemOwn = false; 32 | CRFPPJNI.delete_Tagger(swigCPtr); 33 | } 34 | swigCPtr = 0; 35 | } 36 | } 37 | 38 | public boolean set_model(Model model) { 39 | return CRFPPJNI.Tagger_set_model(swigCPtr, this, Model.getCPtr(model), model); 40 | } 41 | 42 | public void set_vlevel(long vlevel) { 43 | CRFPPJNI.Tagger_set_vlevel(swigCPtr, this, vlevel); 44 | } 45 | 46 | public long vlevel() { 47 | return CRFPPJNI.Tagger_vlevel(swigCPtr, this); 48 | } 49 | 50 | public void set_cost_factor(float cost_factor) { 51 | CRFPPJNI.Tagger_set_cost_factor(swigCPtr, this, cost_factor); 52 | } 53 | 54 | public float cost_factor() { 55 | return CRFPPJNI.Tagger_cost_factor(swigCPtr, this); 56 | } 57 | 58 | public void set_nbest(long nbest) { 59 | CRFPPJNI.Tagger_set_nbest(swigCPtr, this, nbest); 60 | } 61 | 62 | public long nbest() { 63 | return CRFPPJNI.Tagger_nbest(swigCPtr, this); 64 | } 65 | 66 | public boolean add(String str) { 67 | return CRFPPJNI.Tagger_add(swigCPtr, this, str); 68 | } 69 | 70 | public long size() { 71 | return CRFPPJNI.Tagger_size(swigCPtr, this); 72 | } 73 | 74 | public long xsize() { 75 | return CRFPPJNI.Tagger_xsize(swigCPtr, this); 76 | } 77 | 78 | public long dsize() { 79 | return CRFPPJNI.Tagger_dsize(swigCPtr, this); 80 | } 81 | 82 | public long result(long i) { 83 | return CRFPPJNI.Tagger_result(swigCPtr, this, i); 84 | } 85 | 86 | public long answer(long i) { 87 | return CRFPPJNI.Tagger_answer(swigCPtr, this, i); 88 | } 89 | 90 | public long y(long i) { 91 | return CRFPPJNI.Tagger_y(swigCPtr, this, i); 92 | } 93 | 94 | public String y2(long i) { 95 | return CRFPPJNI.Tagger_y2(swigCPtr, this, i); 96 | } 97 | 98 | public String yname(long i) { 99 | return CRFPPJNI.Tagger_yname(swigCPtr, this, i); 100 | } 101 | 102 | public String x(long i, long j) { 103 | return CRFPPJNI.Tagger_x(swigCPtr, this, i, j); 104 | } 105 | 106 | public long ysize() { 107 | return CRFPPJNI.Tagger_ysize(swigCPtr, this); 108 | } 109 | 110 | public double prob(long i, long j) { 111 | return CRFPPJNI.Tagger_prob__SWIG_0(swigCPtr, this, i, j); 112 | } 113 | 114 | public double prob(long i) { 115 | return CRFPPJNI.Tagger_prob__SWIG_1(swigCPtr, this, i); 116 | } 117 | 118 | public double prob() { 119 | return CRFPPJNI.Tagger_prob__SWIG_2(swigCPtr, this); 120 | } 121 | 122 | public void set_penalty(long i, long j, double penalty) { 123 | CRFPPJNI.Tagger_set_penalty(swigCPtr, this, i, j, penalty); 124 | } 125 | 126 | public double penalty(long i, long j) { 127 | return CRFPPJNI.Tagger_penalty(swigCPtr, this, i, j); 128 | } 129 | 130 | public double alpha(long i, long j) { 131 | return CRFPPJNI.Tagger_alpha(swigCPtr, this, i, j); 132 | } 133 | 134 | public double beta(long i, long j) { 135 | return CRFPPJNI.Tagger_beta(swigCPtr, this, i, j); 136 | } 137 | 138 | public double emission_cost(long i, long j) { 139 | return CRFPPJNI.Tagger_emission_cost(swigCPtr, this, i, j); 140 | } 141 | 142 | public double next_transition_cost(long i, long j, long k) { 143 | return CRFPPJNI.Tagger_next_transition_cost(swigCPtr, this, i, j, k); 144 | } 145 | 146 | public double prev_transition_cost(long i, long j, long k) { 147 | return CRFPPJNI.Tagger_prev_transition_cost(swigCPtr, this, i, j, k); 148 | } 149 | 150 | public double best_cost(long i, long j) { 151 | return CRFPPJNI.Tagger_best_cost(swigCPtr, this, i, j); 152 | } 153 | 154 | public double Z() { 155 | return CRFPPJNI.Tagger_Z(swigCPtr, this); 156 | } 157 | 158 | public boolean parse() { 159 | return CRFPPJNI.Tagger_parse__SWIG_0(swigCPtr, this); 160 | } 161 | 162 | public boolean empty() { 163 | return CRFPPJNI.Tagger_empty(swigCPtr, this); 164 | } 165 | 166 | public boolean clear() { 167 | return CRFPPJNI.Tagger_clear(swigCPtr, this); 168 | } 169 | 170 | public boolean next() { 171 | return CRFPPJNI.Tagger_next(swigCPtr, this); 172 | } 173 | 174 | public String parse(String str) { 175 | return CRFPPJNI.Tagger_parse__SWIG_1(swigCPtr, this, str); 176 | } 177 | 178 | public String what() { 179 | return CRFPPJNI.Tagger_what(swigCPtr, this); 180 | } 181 | 182 | public Tagger(String arg) { 183 | this(CRFPPJNI.new_Tagger(arg), true); 184 | } 185 | 186 | } 187 | -------------------------------------------------------------------------------- /feature.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: feature.cpp 1595 2007-02-24 10:18:32Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #include "feature_index.h" 9 | #include "common.h" 10 | #include "node.h" 11 | #include "path.h" 12 | #include "tagger.h" 13 | 14 | namespace CRFPP { 15 | const size_t kMaxContextSize = 8; 16 | 17 | const char *BOS[kMaxContextSize] = { "_B-1", "_B-2", "_B-3", "_B-4", 18 | "_B-5", "_B-6", "_B-7", "_B-8" }; 19 | const char *EOS[kMaxContextSize] = { "_B+1", "_B+2", "_B+3", "_B+4", 20 | "_B+5", "_B+6", "_B+7", "_B+8" }; 21 | 22 | const char *FeatureIndex::getIndex(const char *&p, 23 | size_t pos, 24 | const TaggerImpl &tagger) const { 25 | if (*p++ !='[') { 26 | return 0; 27 | } 28 | 29 | int col = 0; 30 | int row = 0; 31 | 32 | int neg = 1; 33 | if (*p++ == '-') { 34 | neg = -1; 35 | } else { 36 | --p; 37 | } 38 | 39 | for (; *p; ++p) { 40 | switch (*p) { 41 | case '0': case '1': case '2': case '3': case '4': 42 | case '5': case '6': case '7': case '8': case '9': 43 | row = 10 * row +(*p - '0'); 44 | break; 45 | case ',': 46 | ++p; 47 | goto NEXT1; 48 | default: return 0; 49 | } 50 | } 51 | 52 | NEXT1: 53 | 54 | for (; *p; ++p) { 55 | switch (*p) { 56 | case '0': case '1': case '2': case '3': case '4': 57 | case '5': case '6': case '7': case '8': case '9': 58 | col = 10 * col + (*p - '0'); 59 | break; 60 | case ']': goto NEXT2; 61 | default: return 0; 62 | } 63 | } 64 | 65 | NEXT2: 66 | 67 | row *= neg; 68 | 69 | if (row < -static_cast(kMaxContextSize) || 70 | row > static_cast(kMaxContextSize) || 71 | col < 0 || col >= static_cast(tagger.xsize())) { 72 | return 0; 73 | } 74 | 75 | // TODO(taku): very dirty workaround 76 | if (check_max_xsize_) { 77 | max_xsize_ = std::max(max_xsize_, static_cast(col + 1)); 78 | } 79 | 80 | const int idx = pos + row; 81 | if (idx < 0) { 82 | return BOS[-idx-1]; 83 | } 84 | if (idx >= static_cast(tagger.size())) { 85 | return EOS[idx - tagger.size()]; 86 | } 87 | 88 | return tagger.x(idx, col); 89 | } 90 | 91 | bool FeatureIndex::applyRule(string_buffer *os, 92 | const char *p, 93 | size_t pos, 94 | const TaggerImpl& tagger) const { 95 | os->assign(""); // clear 96 | const char *r; 97 | 98 | for (; *p; p++) { 99 | switch (*p) { 100 | default: 101 | *os << *p; 102 | break; 103 | case '%': 104 | switch (*++p) { 105 | case 'x': 106 | ++p; 107 | r = getIndex(p, pos, tagger); 108 | if (!r) { 109 | return false; 110 | } 111 | *os << r; 112 | break; 113 | default: 114 | return false; 115 | } 116 | break; 117 | } 118 | } 119 | 120 | *os << '\0'; 121 | 122 | return true; 123 | } 124 | 125 | void FeatureIndex::rebuildFeatures(TaggerImpl *tagger) const { 126 | size_t fid = tagger->feature_id(); 127 | const size_t thread_id = tagger->thread_id(); 128 | 129 | Allocator *allocator = tagger->allocator(); 130 | allocator->clear_freelist(thread_id); 131 | FeatureCache *feature_cache = allocator->feature_cache(); 132 | 133 | for (size_t cur = 0; cur < tagger->size(); ++cur) { 134 | const int *f = (*feature_cache)[fid++]; 135 | for (size_t i = 0; i < y_.size(); ++i) { 136 | Node *n = allocator->newNode(thread_id); 137 | n->clear(); 138 | n->x = cur; 139 | n->y = i; 140 | n->fvector = f; 141 | tagger->set_node(n, cur, i); 142 | } 143 | } 144 | 145 | for (size_t cur = 1; cur < tagger->size(); ++cur) { 146 | const int *f = (*feature_cache)[fid++]; 147 | for (size_t j = 0; j < y_.size(); ++j) { 148 | for (size_t i = 0; i < y_.size(); ++i) { 149 | Path *p = allocator->newPath(thread_id); 150 | p->clear(); 151 | p->add(tagger->node(cur - 1, j), 152 | tagger->node(cur, i)); 153 | p->fvector = f; 154 | } 155 | } 156 | } 157 | } 158 | 159 | #define ADD { const int id = getID(os.c_str()); \ 160 | if (id != -1) feature.push_back(id); } while (0) 161 | 162 | bool FeatureIndex::buildFeatures(TaggerImpl *tagger) const { 163 | string_buffer os; 164 | std::vector feature; 165 | 166 | FeatureCache *feature_cache = tagger->allocator()->feature_cache(); 167 | tagger->set_feature_id(feature_cache->size()); 168 | 169 | for (size_t cur = 0; cur < tagger->size(); ++cur) { 170 | for (std::vector::const_iterator it 171 | = unigram_templs_.begin(); 172 | it != unigram_templs_.end(); ++it) { 173 | if (!applyRule(&os, it->c_str(), cur, *tagger)) { 174 | return false; 175 | } 176 | ADD; 177 | } 178 | feature_cache->add(feature); 179 | feature.clear(); 180 | } 181 | 182 | for (size_t cur = 1; cur < tagger->size(); ++cur) { 183 | for (std::vector::const_iterator 184 | it = bigram_templs_.begin(); 185 | it != bigram_templs_.end(); ++it) { 186 | if (!applyRule(&os, it->c_str(), cur, *tagger)) { 187 | return false; 188 | } 189 | ADD; 190 | } 191 | feature_cache->add(feature); 192 | feature.clear(); 193 | } 194 | 195 | return true; 196 | } 197 | #undef ADD 198 | } 199 | -------------------------------------------------------------------------------- /mmap.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: mmap.h 1588 2007-02-12 09:03:39Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_MMAP_H_ 9 | #define CRFPP_MMAP_H_ 10 | 11 | #include 12 | #include 13 | 14 | #ifdef HAVE_CONFIG_H 15 | #include "config.h" 16 | #endif 17 | 18 | extern "C" { 19 | 20 | #ifdef HAVE_SYS_TYPES_H 21 | #include 22 | #endif 23 | 24 | #ifdef HAVE_SYS_STAT_H 25 | #include 26 | #endif 27 | 28 | #ifdef HAVE_FCNTL_H 29 | #include 30 | #endif 31 | 32 | #ifdef HAVE_STRING_H 33 | #include 34 | #endif 35 | 36 | #if defined(_WIN32) && !defined(__CYGWIN__) 37 | #ifdef HAVE_WINDOWS_H 38 | #include 39 | #endif 40 | #else 41 | 42 | #ifdef HAVE_SYS_MMAN_H 43 | #include 44 | #endif 45 | 46 | #ifdef HAVE_UNISTD_H 47 | #include 48 | #endif 49 | #endif 50 | } 51 | 52 | #include "common.h" 53 | 54 | #ifndef O_BINARY 55 | #define O_BINARY 0 56 | #endif 57 | 58 | namespace CRFPP { 59 | 60 | template class Mmap { 61 | private: 62 | T *text; 63 | size_t length; 64 | std::string fileName; 65 | whatlog what_; 66 | 67 | #if defined(_WIN32) && !defined(__CYGWIN__) 68 | HANDLE hFile; 69 | HANDLE hMap; 70 | #else 71 | int fd; 72 | int flag; 73 | #endif 74 | 75 | public: 76 | T& operator[](size_t n) { return *(text + n); } 77 | const T& operator[](size_t n) const { return *(text + n); } 78 | T* begin() { return text; } 79 | const T* begin() const { return text; } 80 | T* end() { return text + size(); } 81 | const T* end() const { return text + size(); } 82 | size_t size() { return length/sizeof(T); } 83 | const char *what() { return what_.str(); } 84 | const char *file_name() { return fileName.c_str(); } 85 | size_t file_size() { return length; } 86 | bool empty() { return(length == 0); } 87 | 88 | // This code is imported from sufary, develoved by 89 | // TATUO Yamashita Thanks! 90 | #if defined(_WIN32) && !defined(__CYGWIN__) 91 | bool open(const char *filename, const char *mode = "r") { 92 | this->close(); 93 | unsigned long mode1, mode2, mode3; 94 | fileName = std::string(filename); 95 | 96 | if (std::strcmp(mode, "r") == 0) { 97 | mode1 = GENERIC_READ; 98 | mode2 = PAGE_READONLY; 99 | mode3 = FILE_MAP_READ; 100 | } else if (std::strcmp(mode, "r+") == 0) { 101 | mode1 = GENERIC_READ | GENERIC_WRITE; 102 | mode2 = PAGE_READWRITE; 103 | mode3 = FILE_MAP_ALL_ACCESS; 104 | } else { 105 | CHECK_FALSE(false) << "unknown open mode:" << filename; 106 | } 107 | 108 | hFile = ::CreateFileW(WPATH(filename), mode1, FILE_SHARE_READ, 0, 109 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 110 | CHECK_FALSE(hFile != INVALID_HANDLE_VALUE) 111 | << "CreateFile() failed: " << filename; 112 | 113 | length = ::GetFileSize(hFile, 0); 114 | 115 | hMap = ::CreateFileMapping(hFile, 0, mode2, 0, 0, 0); 116 | CHECK_FALSE(hMap) << "CreateFileMapping() failed: " << filename; 117 | 118 | text = reinterpret_cast(::MapViewOfFile(hMap, mode3, 0, 0, 0)); 119 | CHECK_FALSE(text) << "MapViewOfFile() failed: " << filename; 120 | 121 | return true; 122 | } 123 | 124 | void close() { 125 | if (text) { ::UnmapViewOfFile(text); } 126 | if (hFile != INVALID_HANDLE_VALUE) { 127 | ::CloseHandle(hFile); 128 | hFile = INVALID_HANDLE_VALUE; 129 | } 130 | if (hMap) { 131 | ::CloseHandle(hMap); 132 | hMap = 0; 133 | } 134 | text = 0; 135 | } 136 | 137 | Mmap(): text(0), hFile(INVALID_HANDLE_VALUE), hMap(0) {} 138 | 139 | #else 140 | 141 | bool open(const char *filename, const char *mode = "r") { 142 | this->close(); 143 | struct stat st; 144 | fileName = std::string(filename); 145 | 146 | if (std::strcmp(mode, "r") == 0) 147 | flag = O_RDONLY; 148 | else if (std::strcmp(mode, "r+") == 0) 149 | flag = O_RDWR; 150 | else 151 | CHECK_FALSE(false) << "unknown open mode: " << filename; 152 | 153 | CHECK_FALSE((fd = ::open(filename, flag | O_BINARY)) >= 0) 154 | << "open failed: " << filename; 155 | 156 | CHECK_FALSE(fstat(fd, &st) >= 0) 157 | << "failed to get file size: " << filename; 158 | 159 | length = st.st_size; 160 | 161 | #ifdef HAVE_MMAP 162 | int prot = PROT_READ; 163 | if (flag == O_RDWR) prot |= PROT_WRITE; 164 | char *p; 165 | CHECK_FALSE((p = reinterpret_cast 166 | (mmap(0, length, prot, MAP_SHARED, fd, 0))) 167 | != MAP_FAILED) 168 | << "mmap() failed: " << filename; 169 | 170 | text = reinterpret_cast(p); 171 | #else 172 | text = new T[length]; 173 | CHECK_FALSE(read(fd, text, length) >= 0) 174 | << "read() failed: " << filename; 175 | #endif 176 | ::close(fd); 177 | fd = -1; 178 | 179 | return true; 180 | } 181 | 182 | void close() { 183 | if (fd >= 0) { 184 | ::close(fd); 185 | fd = -1; 186 | } 187 | 188 | if (text) { 189 | #ifdef HAVE_MMAP 190 | munmap(reinterpret_cast(text), length); 191 | text = 0; 192 | #else 193 | if (flag == O_RDWR) { 194 | int fd2; 195 | if ((fd2 = ::open(fileName.c_str(), O_RDWR)) >= 0) { 196 | write(fd2, text, length); 197 | ::close(fd2); 198 | } 199 | } 200 | delete [] text; 201 | #endif 202 | } 203 | 204 | text = 0; 205 | } 206 | 207 | Mmap(): text(0), fd(-1) {} 208 | #endif 209 | 210 | virtual ~Mmap() { this->close(); } 211 | }; 212 | } 213 | #endif 214 | -------------------------------------------------------------------------------- /python/CRFPP.py: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by SWIG (http://www.swig.org). 2 | # Version 2.0.4 3 | # 4 | # Do not make changes to this file unless you know what you are doing--modify 5 | # the SWIG interface file instead. 6 | 7 | 8 | 9 | from sys import version_info 10 | if version_info >= (2,6,0): 11 | def swig_import_helper(): 12 | from os.path import dirname 13 | import imp 14 | fp = None 15 | try: 16 | fp, pathname, description = imp.find_module('_CRFPP', [dirname(__file__)]) 17 | except ImportError: 18 | import _CRFPP 19 | return _CRFPP 20 | if fp is not None: 21 | try: 22 | _mod = imp.load_module('_CRFPP', fp, pathname, description) 23 | finally: 24 | fp.close() 25 | return _mod 26 | _CRFPP = swig_import_helper() 27 | del swig_import_helper 28 | else: 29 | import _CRFPP 30 | del version_info 31 | try: 32 | _swig_property = property 33 | except NameError: 34 | pass # Python < 2.2 doesn't have 'property'. 35 | def _swig_setattr_nondynamic(self,class_type,name,value,static=1): 36 | if (name == "thisown"): return self.this.own(value) 37 | if (name == "this"): 38 | if type(value).__name__ == 'SwigPyObject': 39 | self.__dict__[name] = value 40 | return 41 | method = class_type.__swig_setmethods__.get(name,None) 42 | if method: return method(self,value) 43 | if (not static): 44 | self.__dict__[name] = value 45 | else: 46 | raise AttributeError("You cannot add attributes to %s" % self) 47 | 48 | def _swig_setattr(self,class_type,name,value): 49 | return _swig_setattr_nondynamic(self,class_type,name,value,0) 50 | 51 | def _swig_getattr(self,class_type,name): 52 | if (name == "thisown"): return self.this.own() 53 | method = class_type.__swig_getmethods__.get(name,None) 54 | if method: return method(self) 55 | raise AttributeError(name) 56 | 57 | def _swig_repr(self): 58 | try: strthis = "proxy of " + self.this.__repr__() 59 | except: strthis = "" 60 | return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) 61 | 62 | try: 63 | _object = object 64 | _newclass = 1 65 | except AttributeError: 66 | class _object : pass 67 | _newclass = 0 68 | 69 | 70 | class Model(_object): 71 | __swig_setmethods__ = {} 72 | __setattr__ = lambda self, name, value: _swig_setattr(self, Model, name, value) 73 | __swig_getmethods__ = {} 74 | __getattr__ = lambda self, name: _swig_getattr(self, Model, name) 75 | __repr__ = _swig_repr 76 | def getTemplate(self): return _CRFPP.Model_getTemplate(self) 77 | def createTagger(self): return _CRFPP.Model_createTagger(self) 78 | def what(self): return _CRFPP.Model_what(self) 79 | __swig_destroy__ = _CRFPP.delete_Model 80 | __del__ = lambda self : None; 81 | def __init__(self, *args): 82 | this = _CRFPP.new_Model(*args) 83 | try: self.this.append(this) 84 | except: self.this = this 85 | Model_swigregister = _CRFPP.Model_swigregister 86 | Model_swigregister(Model) 87 | 88 | class Tagger(_object): 89 | __swig_setmethods__ = {} 90 | __setattr__ = lambda self, name, value: _swig_setattr(self, Tagger, name, value) 91 | __swig_getmethods__ = {} 92 | __getattr__ = lambda self, name: _swig_getattr(self, Tagger, name) 93 | __repr__ = _swig_repr 94 | def set_model(self, *args): return _CRFPP.Tagger_set_model(self, *args) 95 | def set_vlevel(self, *args): return _CRFPP.Tagger_set_vlevel(self, *args) 96 | def vlevel(self): return _CRFPP.Tagger_vlevel(self) 97 | def set_cost_factor(self, *args): return _CRFPP.Tagger_set_cost_factor(self, *args) 98 | def cost_factor(self): return _CRFPP.Tagger_cost_factor(self) 99 | def set_nbest(self, *args): return _CRFPP.Tagger_set_nbest(self, *args) 100 | def nbest(self): return _CRFPP.Tagger_nbest(self) 101 | def add(self, *args): return _CRFPP.Tagger_add(self, *args) 102 | def size(self): return _CRFPP.Tagger_size(self) 103 | def xsize(self): return _CRFPP.Tagger_xsize(self) 104 | def dsize(self): return _CRFPP.Tagger_dsize(self) 105 | def result(self, *args): return _CRFPP.Tagger_result(self, *args) 106 | def answer(self, *args): return _CRFPP.Tagger_answer(self, *args) 107 | def y(self, *args): return _CRFPP.Tagger_y(self, *args) 108 | def y2(self, *args): return _CRFPP.Tagger_y2(self, *args) 109 | def yname(self, *args): return _CRFPP.Tagger_yname(self, *args) 110 | def x(self, *args): return _CRFPP.Tagger_x(self, *args) 111 | def ysize(self): return _CRFPP.Tagger_ysize(self) 112 | def prob(self, *args): return _CRFPP.Tagger_prob(self, *args) 113 | def set_penalty(self, *args): return _CRFPP.Tagger_set_penalty(self, *args) 114 | def penalty(self, *args): return _CRFPP.Tagger_penalty(self, *args) 115 | def alpha(self, *args): return _CRFPP.Tagger_alpha(self, *args) 116 | def beta(self, *args): return _CRFPP.Tagger_beta(self, *args) 117 | def emission_cost(self, *args): return _CRFPP.Tagger_emission_cost(self, *args) 118 | def next_transition_cost(self, *args): return _CRFPP.Tagger_next_transition_cost(self, *args) 119 | def prev_transition_cost(self, *args): return _CRFPP.Tagger_prev_transition_cost(self, *args) 120 | def best_cost(self, *args): return _CRFPP.Tagger_best_cost(self, *args) 121 | def Z(self): return _CRFPP.Tagger_Z(self) 122 | def empty(self): return _CRFPP.Tagger_empty(self) 123 | def clear(self): return _CRFPP.Tagger_clear(self) 124 | def next(self): return _CRFPP.Tagger_next(self) 125 | def parse(self, *args): return _CRFPP.Tagger_parse(self, *args) 126 | def what(self): return _CRFPP.Tagger_what(self) 127 | __swig_destroy__ = _CRFPP.delete_Tagger 128 | __del__ = lambda self : None; 129 | def __init__(self, *args): 130 | this = _CRFPP.new_Tagger(*args) 131 | try: self.this.append(this) 132 | except: self.this = this 133 | Tagger_swigregister = _CRFPP.Tagger_swigregister 134 | Tagger_swigregister(Tagger) 135 | 136 | VERSION = _CRFPP.VERSION 137 | # This file is compatible with both classic and new-style classes. 138 | 139 | 140 | -------------------------------------------------------------------------------- /param.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: param.cpp 1587 2007-02-12 09:00:36Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #include 9 | #include 10 | #include "param.h" 11 | #include "common.h" 12 | 13 | #ifdef HAVE_CONFIG_H 14 | #include "config.h" 15 | #endif 16 | 17 | namespace CRFPP { 18 | namespace { 19 | 20 | void init_param(std::string *help, 21 | std::string *version, 22 | const std::string &system_name, 23 | const Option *opts) { 24 | *help = std::string(COPYRIGHT) + "\nUsage: " + 25 | system_name + " [options] files\n"; 26 | 27 | *version = std::string(PACKAGE) + " of " + VERSION + '\n'; 28 | 29 | size_t max = 0; 30 | for (size_t i = 0; opts[i].name; ++i) { 31 | size_t l = 1 + std::strlen(opts[i].name); 32 | if (opts[i].arg_description) 33 | l += (1 + std::strlen(opts[i].arg_description)); 34 | max = std::max(l, max); 35 | } 36 | 37 | for (size_t i = 0; opts[i].name; ++i) { 38 | size_t l = std::strlen(opts[i].name); 39 | if (opts[i].arg_description) 40 | l += (1 + std::strlen(opts[i].arg_description)); 41 | *help += " -"; 42 | *help += opts[i].short_name; 43 | *help += ", --"; 44 | *help += opts[i].name; 45 | if (opts[i].arg_description) { 46 | *help += '='; 47 | *help += opts[i].arg_description; 48 | } 49 | for (; l <= max; l++) *help += ' '; 50 | *help += opts[i].description; 51 | *help += '\n'; 52 | } 53 | 54 | *help += '\n'; 55 | return; 56 | } 57 | } // namespace 58 | 59 | void Param::dump_config(std::ostream *os) const { 60 | for (std::map::const_iterator it = conf_.begin(); 61 | it != conf_.end(); 62 | ++it) { 63 | *os << it->first << ": " << it->second << std::endl; 64 | } 65 | } 66 | 67 | bool Param::load(const char *filename) { 68 | std::ifstream ifs(WPATH(filename)); 69 | 70 | CHECK_FALSE(ifs) << "no such file or directory: " << filename; 71 | 72 | std::string line; 73 | while (std::getline(ifs, line)) { 74 | if (!line.size() || 75 | (line.size() && (line[0] == ';' || line[0] == '#'))) continue; 76 | 77 | size_t pos = line.find('='); 78 | CHECK_FALSE(pos != std::string::npos) << "format error: " << line; 79 | 80 | size_t s1, s2; 81 | for (s1 = pos+1; s1 < line.size() && isspace(line[s1]); s1++); 82 | for (s2 = pos-1; static_cast(s2) >= 0 && isspace(line[s2]); s2--); 83 | const std::string value = line.substr(s1, line.size() - s1); 84 | const std::string key = line.substr(0, s2 + 1); 85 | set(key.c_str(), value, false); 86 | } 87 | 88 | return true; 89 | } 90 | 91 | bool Param::open(int argc, char **argv, const Option *opts) { 92 | int ind = 0; 93 | int _errno = 0; 94 | 95 | #define GOTO_FATAL_ERROR(n) { \ 96 | _errno = n; \ 97 | goto FATAL_ERROR; } while (0) 98 | 99 | if (argc <= 0) { 100 | system_name_ = "unknown"; 101 | return true; // this is not error 102 | } 103 | 104 | system_name_ = std::string(argv[0]); 105 | 106 | init_param(&help_, &version_, system_name_, opts); 107 | 108 | for (size_t i = 0; opts[i].name; ++i) { 109 | if (opts[i].default_value) set 110 | (opts[i].name, opts[i].default_value); 111 | } 112 | 113 | for (ind = 1; ind < argc; ind++) { 114 | if (argv[ind][0] == '-') { 115 | // long options 116 | if (argv[ind][1] == '-') { 117 | char *s; 118 | for (s = &argv[ind][2]; *s != '\0' && *s != '='; s++); 119 | size_t len = (size_t)(s - &argv[ind][2]); 120 | if (len == 0) return true; // stop the scanning 121 | 122 | bool hit = false; 123 | size_t i = 0; 124 | for (i = 0; opts[i].name; ++i) { 125 | size_t nlen = std::strlen(opts[i].name); 126 | if (nlen == len && std::strncmp(&argv[ind][2], 127 | opts[i].name, len) == 0) { 128 | hit = true; 129 | break; 130 | } 131 | } 132 | 133 | if (!hit) GOTO_FATAL_ERROR(0); 134 | 135 | if (opts[i].arg_description) { 136 | if (*s == '=') { 137 | if (*(s+1) == '\0') GOTO_FATAL_ERROR(1); 138 | set(opts[i].name, s+1); 139 | } else { 140 | if (argc == (ind+1)) GOTO_FATAL_ERROR(1); 141 | set(opts[i].name, argv[++ind]); 142 | } 143 | } else { 144 | if (*s == '=') GOTO_FATAL_ERROR(2); 145 | set(opts[i].name, 1); 146 | } 147 | 148 | // short options 149 | } else if (argv[ind][1] != '\0') { 150 | size_t i = 0; 151 | bool hit = false; 152 | for (i = 0; opts[i].name; ++i) { 153 | if (opts[i].short_name == argv[ind][1]) { 154 | hit = true; 155 | break; 156 | } 157 | } 158 | 159 | if (!hit) GOTO_FATAL_ERROR(0); 160 | 161 | if (opts[i].arg_description) { 162 | if (argv[ind][2] != '\0') { 163 | set(opts[i].name, &argv[ind][2]); 164 | } else { 165 | if (argc == (ind+1)) GOTO_FATAL_ERROR(1); 166 | set(opts[i].name, argv[++ind]); 167 | } 168 | } else { 169 | if (argv[ind][2] != '\0') GOTO_FATAL_ERROR(2); 170 | set(opts[i].name, 1); 171 | } 172 | } 173 | } else { 174 | rest_.push_back(std::string(argv[ind])); // others 175 | } 176 | } 177 | 178 | return true; 179 | 180 | FATAL_ERROR: 181 | switch (_errno) { 182 | case 0: WHAT << "unrecognized option `" << argv[ind] << "`"; break; 183 | case 1: WHAT << "`" << argv[ind] << "` requires an argument"; break; 184 | case 2: WHAT << "`" << argv[ind] << "` doesn't allow an argument"; break; 185 | } 186 | return false; 187 | } 188 | 189 | void Param::clear() { 190 | conf_.clear(); 191 | rest_.clear(); 192 | } 193 | 194 | bool Param::open(const char *arg, const Option *opts) { 195 | char str[BUF_SIZE]; 196 | std::strncpy(str, arg, sizeof(str)); 197 | char* ptr[64]; 198 | unsigned int size = 1; 199 | ptr[0] = const_cast(PACKAGE); 200 | 201 | for (char *p = str; *p;) { 202 | while (isspace(*p)) *p++ = '\0'; 203 | if (*p == '\0') break; 204 | ptr[size++] = p; 205 | if (size == sizeof(ptr)) break; 206 | while (*p && !isspace(*p)) p++; 207 | } 208 | 209 | return open(size, ptr, opts); 210 | } 211 | 212 | int Param::help_version() const { 213 | if (get("help")) { 214 | std::cout << help(); 215 | return 0; 216 | } 217 | 218 | if (get("version")) { 219 | std::cout << version(); 220 | return 0; 221 | } 222 | 223 | return 1; 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /common.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: common.h 1588 2007-02-12 09:03:39Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_COMMON_H_ 9 | #define CRFPP_COMMON_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #if defined(_WIN32) && !defined(__CYGWIN__) 21 | #define NOMINMAX 22 | #include 23 | #endif 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include "config.h" 27 | #endif 28 | 29 | #define COPYRIGHT "CRF++: Yet Another CRF Tool Kit\nCopyright (C) " \ 30 | "2005-2013 Taku Kudo, All rights reserved.\n" 31 | #define MODEL_VERSION 100 32 | 33 | #if defined(_WIN32) && !defined(__CYGWIN__) 34 | # define OUTPUT_MODE std::ios::binary|std::ios::out 35 | #else 36 | # define OUTPUT_MODE std::ios::out 37 | #endif 38 | 39 | #define BUF_SIZE 8192 40 | 41 | namespace CRFPP { 42 | // helper functions defined in the paper 43 | inline double sigma(double x) { 44 | if (x > 0) return 1.0; 45 | else if (x < 0) return -1.0; 46 | return 0.0; 47 | } 48 | 49 | template 50 | inline size_t tokenizeCSV(char *str, 51 | Iterator out, size_t max) { 52 | char *eos = str + std::strlen(str); 53 | char *start = 0; 54 | char *end = 0; 55 | size_t n = 0; 56 | 57 | for (; str < eos; ++str) { 58 | while (*str == ' ' || *str == '\t') ++str; // skip white spaces 59 | bool inquote = false; 60 | if (*str == '"') { 61 | start = ++str; 62 | end = start; 63 | for (; str < eos; ++str) { 64 | if (*str == '"') { 65 | str++; 66 | if (*str != '"') 67 | break; 68 | } 69 | *end++ = *str; 70 | } 71 | inquote = true; 72 | str = std::find(str, eos, ','); 73 | } else { 74 | start = str; 75 | str = std::find(str, eos, ','); 76 | end = str; 77 | } 78 | if (max-- > 1) *end = '\0'; 79 | *out++ = start; 80 | ++n; 81 | if (max == 0) break; 82 | } 83 | 84 | return n; 85 | } 86 | 87 | template 88 | inline size_t tokenize(char *str, const char *del, 89 | Iterator out, size_t max) { 90 | char *stre = str + std::strlen(str); 91 | const char *dele = del + std::strlen(del); 92 | size_t size = 0; 93 | 94 | while (size < max) { 95 | char *n = std::find_first_of(str, stre, del, dele); 96 | *n = '\0'; 97 | *out++ = str; 98 | ++size; 99 | if (n == stre) break; 100 | str = n + 1; 101 | } 102 | 103 | return size; 104 | } 105 | 106 | // continus run of space is regarded as one space 107 | template 108 | inline size_t tokenize2(char *str, const char *del, 109 | Iterator out, size_t max) { 110 | char *stre = str + std::strlen(str); 111 | const char *dele = del + std::strlen(del); 112 | size_t size = 0; 113 | 114 | while (size < max) { 115 | char *n = std::find_first_of(str, stre, del, dele); 116 | *n = '\0'; 117 | if (*str != '\0') { 118 | *out++ = str; 119 | ++size; 120 | } 121 | if (n == stre) break; 122 | str = n + 1; 123 | } 124 | 125 | return size; 126 | } 127 | 128 | void inline dtoa(double val, char *s) { 129 | std::sprintf(s, "%-16f", val); 130 | char *p = s; 131 | for (; *p != ' '; ++p) {} 132 | *p = '\0'; 133 | return; 134 | } 135 | 136 | template inline void itoa(T val, char *s) { 137 | char *t; 138 | T mod; 139 | 140 | if (val < 0) { 141 | *s++ = '-'; 142 | val = -val; 143 | } 144 | t = s; 145 | 146 | while (val) { 147 | mod = val % 10; 148 | *t++ = static_cast(mod)+ '0'; 149 | val /= 10; 150 | } 151 | 152 | if (s == t) *t++ = '0'; 153 | *t = '\0'; 154 | std::reverse(s, t); 155 | 156 | return; 157 | } 158 | 159 | template 160 | inline void uitoa(T val, char *s) { 161 | char *t; 162 | T mod; 163 | t = s; 164 | 165 | while (val) { 166 | mod = val % 10; 167 | *t++ = static_cast(mod) + '0'; 168 | val /= 10; 169 | } 170 | 171 | if (s == t) *t++ = '0'; 172 | *t = '\0'; 173 | std::reverse(s, t); 174 | 175 | return; 176 | } 177 | 178 | #if defined(_WIN32) && !defined(__CYGWIN__) 179 | std::wstring Utf8ToWide(const std::string &input); 180 | std::string WideToUtf8(const std::wstring &input); 181 | #endif 182 | 183 | #if defined(_WIN32) && !defined(__CYGWIN__) 184 | #define WPATH(path) (CRFPP::Utf8ToWide(path).c_str()) 185 | #else 186 | #define WPATH(path) (path) 187 | #endif 188 | 189 | #define _ITOA(_n) do { \ 190 | char buf[64]; \ 191 | itoa(_n, buf); \ 192 | append(buf); \ 193 | return *this; } while (0) 194 | 195 | #define _UITOA(_n) do { \ 196 | char buf[64]; \ 197 | uitoa(_n, buf); \ 198 | append(buf); \ 199 | return *this; } while (0) 200 | 201 | #define _DTOA(_n) do { \ 202 | char buf[64]; \ 203 | dtoa(_n, buf); \ 204 | append(buf); \ 205 | return *this; } while (0) 206 | 207 | class string_buffer: public std::string { 208 | public: 209 | string_buffer& operator<<(double _n) { _DTOA(_n); } 210 | string_buffer& operator<<(short int _n) { _ITOA(_n); } 211 | string_buffer& operator<<(int _n) { _ITOA(_n); } 212 | string_buffer& operator<<(long int _n) { _ITOA(_n); } 213 | string_buffer& operator<<(unsigned short int _n) { _UITOA(_n); } 214 | string_buffer& operator<<(unsigned int _n) { _UITOA(_n); } 215 | // string_buffer& operator<<(unsigned long int _n) { _UITOA(_n); } 216 | string_buffer& operator<<(size_t _n) { _UITOA(_n); } 217 | string_buffer& operator<<(char _n) { 218 | push_back(_n); 219 | return *this; 220 | } 221 | string_buffer& operator<<(const char* _n) { 222 | append(_n); 223 | return *this; 224 | } 225 | string_buffer& operator<<(const std::string& _n) { 226 | append(_n); 227 | return *this; 228 | } 229 | }; 230 | 231 | class die { 232 | public: 233 | die() {} 234 | ~die() { 235 | std::cerr << std::endl; 236 | exit(-1); 237 | } 238 | int operator&(std::ostream&) { return 0; } 239 | }; 240 | 241 | struct whatlog { 242 | std::ostringstream stream_; 243 | std::string str_; 244 | const char *str() { 245 | str_ = stream_.str(); 246 | return str_.c_str(); 247 | } 248 | }; 249 | 250 | class wlog { 251 | public: 252 | wlog(whatlog *what) : what_(what) { 253 | what_->stream_.clear(); 254 | } 255 | bool operator&(std::ostream &) { 256 | return false; 257 | } 258 | private: 259 | whatlog *what_; 260 | }; 261 | } // CRFPP 262 | 263 | #define WHAT what_.stream_ 264 | 265 | #define CHECK_FALSE(condition) \ 266 | if (condition) {} else return \ 267 | wlog(&what_) & what_.stream_ << \ 268 | __FILE__ << "(" << __LINE__ << ") [" << #condition << "] " 269 | 270 | #define CHECK_DIE(condition) \ 271 | (condition) ? 0 : die() & std::cerr << __FILE__ << \ 272 | "(" << __LINE__ << ") [" << #condition << "] " 273 | 274 | #endif 275 | -------------------------------------------------------------------------------- /configure.in: -------------------------------------------------------------------------------- 1 | dnl Process this file with autoconf to produce a configure script. 2 | AC_INIT(crf_learn.cpp) 3 | AH_TEMPLATE([HAVE_TLS_KEYWORD], []) 4 | AH_TEMPLATE([HAVE_SYS_CONF_SC_NPROCESSORS_CONF], []) 5 | AM_INIT_AUTOMAKE(CRF++, 0.59) 6 | 7 | dnl Checks for programs. 8 | AC_PROG_CC 9 | AC_PROG_CXX 10 | AC_PROG_GCC_TRADITIONAL 11 | AC_PROG_MAKE_SET 12 | AC_ISC_POSIX 13 | AC_CYGWIN 14 | AC_LANG_CPLUSPLUS 15 | AC_PROG_LIBTOOL 16 | AC_CONFIG_MACRO_DIR([m4]) 17 | 18 | dnl Checks for libraries. 19 | 20 | dnl Checks for header files. 21 | AC_HEADER_STDC 22 | AC_CHECK_HEADERS(string.h stdlib.h unistd.h fcntl.h \ 23 | sys/stat.h sys/mman.h sys/times.h \ 24 | ctype.h sys/types.h math.h pthread.h) 25 | 26 | AC_TYPE_SIZE_T 27 | 28 | dnl Checks for libraries. 29 | AC_CHECK_LIB(m,pow) 30 | AC_CHECK_LIB(m,exp) 31 | AC_CHECK_LIB(m,log) 32 | AC_CHECK_LIB(pthread,pthread_create) 33 | AC_CHECK_LIB(pthread,pthread_join) 34 | AC_FUNC_MMAP 35 | 36 | dnl 37 | dnl Check for GNU make 38 | dnl 39 | AC_MSG_CHECKING(whether make is GNU Make) 40 | if $ac_make --version 2>/dev/null | grep '^GNU Make ' >/dev/null ; then 41 | AC_MSG_RESULT(yes) 42 | else 43 | AC_MSG_RESULT(no) 44 | if test "$host_vendor" = "sun" ; then 45 | AC_MSG_ERROR("SUN make does not work for building maxent. Please install GNU make") 46 | fi 47 | fi 48 | 49 | dnl 50 | dnl check gcc 51 | dnl 52 | if test -n "$GCC"; then 53 | CFLAGS="-O3 -Wall"; 54 | CXXFLAGS="-O3 -Wall"; 55 | fi 56 | 57 | AC_DEFUN(ADD_CC_FLAG, [ 58 | AC_MSG_CHECKING(whether ${CC-cc} accepts $1) 59 | AC_LANG_SAVE 60 | AC_LANG_C 61 | XCFLAGS="$CFLAGS" 62 | CFLAGS="$CFLAGS $1" 63 | AC_TRY_LINK([], [], 64 | [AC_MSG_RESULT([ ok, adding $1 to CFLAGS])], 65 | [CFLAGS="$XCFLAGS"]) 66 | AC_LANG_RESTORE 67 | ]) 68 | 69 | AC_DEFUN(ADD_CXX_FLAG, [ 70 | AC_MSG_CHECKING(whether ${CXX-c++} accepts $1) 71 | AC_LANG_SAVE 72 | AC_LANG_CPLUSPLUS 73 | XCXXFLAGS="$CXXFLAGS" 74 | CXXFLAGS="$CXXFLAGS $1" 75 | AC_TRY_LINK([], [], 76 | [AC_MSG_RESULT([ ok, adding $1 to CXXFLAGS])], 77 | [CXXFLAGS="$XCXXFLAGS"]) 78 | AC_LANG_RESTORE 79 | ]) 80 | 81 | # On Intel systems with gcc, we may need to compile with -mieee-fp to 82 | # get full support for IEEE floating point. 83 | # 84 | # On Alpha/OSF systems, we need -mieee. 85 | # 86 | # On AIX systems, we need to limit the amount of stuff that goes in 87 | # the TOC. 88 | case "$host" in 89 | changequote(,)dnl 90 | i[3456789]86-*-*) 91 | changequote([,])dnl 92 | ADD_CC_FLAG(-mieee-fp) 93 | ADD_CXX_FLAG(-mieee-fp) 94 | ;; 95 | alpha*-*-*) 96 | ADD_CC_FLAG(-mieee) 97 | ADD_CXX_FLAG(-mieee) 98 | ;; 99 | *ibm-aix4*) 100 | ADD_CC_FLAG(-mminimal-toc) 101 | ADD_CXX_FLAG(-mminimal-toc) 102 | ;; 103 | esac 104 | 105 | dnl 106 | dnl check C++ features 107 | dnl 108 | AC_DEFUN(CHECK_CXX_STL, [ 109 | AC_MSG_CHECKING(if ${CXX-c++} supports stl <$1> (required)) 110 | AC_TRY_COMPILE( 111 | [ 112 | #include <$1> 113 | ], [ 114 | ; 115 | ], [ 116 | ac_stl_$1=yes 117 | ], [ 118 | config_error=yes 119 | AC_WARN(${CXX-c++} stl <$1> does not work) 120 | ]) 121 | AC_MSG_RESULT([$ac_stl_$1]) 122 | ]) 123 | 124 | CHECK_CXX_STL(string) 125 | CHECK_CXX_STL(vector) 126 | CHECK_CXX_STL(map) 127 | CHECK_CXX_STL(set) 128 | CHECK_CXX_STL(iostream) 129 | CHECK_CXX_STL(fstream) 130 | CHECK_CXX_STL(sstream) 131 | CHECK_CXX_STL(stdexcept) 132 | 133 | # check for const_cast 134 | AC_MSG_CHECKING([if ${CXX-c++} supports template (required)]) 135 | AC_TRY_COMPILE( 136 | [ 137 | template T foo (T &i) { return i++; }; 138 | ],[ 139 | int i = 0; 140 | double d = 0.0; 141 | foo(i); foo(d); 142 | ],[ 143 | ac_template=yes 144 | ],[ 145 | AC_WARN(${CXX-c++} template does not work) 146 | config_error=yes 147 | ]) 148 | AC_MSG_RESULT([$ac_template]) 149 | 150 | # check for const_cast 151 | AC_MSG_CHECKING([if ${CXX-c++} supports const_cast<> (required)]) 152 | AC_TRY_COMPILE( 153 | [ 154 | class foo; 155 | ],[ 156 | const foo *c=0; 157 | foo *c1=const_cast(c); 158 | ],[ 159 | ac_const_cast=yes 160 | ],[ 161 | AC_WARN(${CXX-c++} const_cast<> does not work) 162 | config_error=yes 163 | ]) 164 | AC_MSG_RESULT([$ac_const_cast]) 165 | 166 | # check for static_cast<> 167 | AC_MSG_CHECKING(if ${CXX-c++} supports static_cast<> (required)) 168 | AC_TRY_COMPILE( 169 | [ 170 | class foo; 171 | ],[ 172 | foo *c = 0; 173 | void *c1 = static_cast(c); 174 | ],[ 175 | ac_static_cast=yes 176 | ],[ 177 | AC_WARN(${CXX-c++} static_cast<> does not work) 178 | config_error=yes 179 | ]) 180 | AC_MSG_RESULT([$ac_static_cast]) 181 | 182 | # check for dynamic_cast<> 183 | AC_MSG_CHECKING(if ${CXX-c++} supports dynamic_cast<> (required)) 184 | AC_TRY_COMPILE( 185 | [ 186 | class foo {}; 187 | class bar: public foo {}; 188 | ],[ 189 | bar *c = 0; 190 | foo *c1 = dynamic_cast(c); 191 | ],[ 192 | ac_dynamic_cast=yes 193 | ],[ 194 | AC_WARN(${CXX-c++} dynamic_cast<> does not work) 195 | config_error=yes 196 | ]) 197 | AC_MSG_RESULT([$ac_dynamic_cast]) 198 | 199 | # check for try 200 | AC_MSG_CHECKING(if ${CXX-c++} supports exception handler (required)) 201 | AC_TRY_COMPILE( 202 | [ 203 | ; 204 | ],[ 205 | try { 206 | int i = 0; 207 | } 208 | catch (char *e) { 209 | } 210 | catch (...) { 211 | } 212 | ],[ 213 | ac_exception=yes 214 | ],[ 215 | AC_WARN(${CXX-c++} exception does not work) 216 | config_error=yes 217 | ]) 218 | AC_MSG_RESULT([$ac_exception]) 219 | 220 | # check for namespaces 221 | AC_MSG_CHECKING(if ${CXX-c++} supports namespaces (required) ) 222 | AC_TRY_COMPILE( 223 | [ 224 | namespace Foo { struct A {}; } 225 | using namespace Foo; 226 | ],[ 227 | A a; 228 | ],[ 229 | ac_namespaces=yes 230 | dnl AC_DEFINE(HAVE_CXX_NAMESPACE) 231 | ],[ 232 | config_error=yes 233 | ac_namespaces=no 234 | ]) 235 | AC_MSG_RESULT([$ac_namespaces]) 236 | 237 | 238 | dnl __thread keyword 239 | AC_MSG_CHECKING([if ${CXX-c++} supports __thread (optional)]) 240 | AC_TRY_COMPILE( 241 | [ 242 | __thread int a = 0; 243 | ],[ 244 | a = 10; 245 | ],[ 246 | enable_tls=yes 247 | ],[ 248 | enable_tls=no 249 | ]) 250 | AC_MSG_RESULT([$enable_tls]) 251 | 252 | if test "$enable_tls" = "no"; then 253 | AC_MSG_WARN([__thread keyword is not supported on this environment. \ 254 | Error handling of CRF++, e.g., CRFPP::getLastError(), is not thread safe.]) 255 | else 256 | AC_DEFINE([HAVE_TLS_KEYWORD]) 257 | fi 258 | 259 | AC_MSG_CHECKING([if ${CXX-c++} supports _SC_NPROCESSORS_CONF (optional)]) 260 | AC_TRY_COMPILE( 261 | [ 262 | #include 263 | long n = sysconf(_SC_NPROCESSORS_CONF); 264 | ],[ 265 | n = 10; 266 | ],[ 267 | enable_sysconf_sc_nprocessors_conf=yes 268 | ],[ 269 | enable_sysconf_sc_nprocessors_conf=no 270 | ]) 271 | AC_MSG_RESULT([$enable_sysconf_sc_nprocessors_conf]) 272 | 273 | if test "$enable_sysconf_sc_nprocessors_conf" = "no"; then 274 | AC_MSG_WARN([_SC_NPROCESSORS_CONF on this environment.]) 275 | else 276 | AC_DEFINE([HAVE_SYS_CONF_SC_NPROCESSORS_CONF]) 277 | fi 278 | 279 | AC_MSG_CHECKING(if ${CXX-c++} environment provides all required features) 280 | if test "x$config_error" = xyes ; then 281 | AC_MSG_RESULT([no]) 282 | AC_MSG_ERROR([Your compiler is not powerful enough to compile CRF++. \ 283 | If it should be, see config.log for more information of why it failed.]) 284 | fi 285 | AC_MSG_RESULT([yes]) 286 | 287 | AC_SUBST(datarootdir) 288 | AM_CONFIG_HEADER(config.h) 289 | AC_OUTPUT([Makefile Makefile.msvc swig/version.h]) 290 | 291 | -------------------------------------------------------------------------------- /tagger.h: -------------------------------------------------------------------------------- 1 | // 2 | // CRF++ -- Yet Another CRF toolkit 3 | // 4 | // $Id: tagger.h 1588 2007-02-12 09:03:39Z taku $; 5 | // 6 | // Copyright(C) 2005-2007 Taku Kudo 7 | // 8 | #ifndef CRFPP_TAGGER_H_ 9 | #define CRFPP_TAGGER_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "param.h" 15 | #include "crfpp.h" 16 | #include "scoped_ptr.h" 17 | #include "feature_index.h" 18 | 19 | namespace CRFPP { 20 | 21 | static inline double toprob(Node *n, double Z) { 22 | return std::exp(n->alpha + n->beta - n->cost - Z); 23 | } 24 | 25 | class Allocator; 26 | 27 | class ModelImpl : public Model { 28 | public: 29 | ModelImpl() : nbest_(0), vlevel_(0) {} 30 | virtual ~ModelImpl() {} 31 | bool open(int argc, char** argv); 32 | bool open(const char* arg); 33 | bool openFromArray(int argc, char** argv, 34 | const char *buf, size_t size); 35 | bool openFromArray(const char* arg, 36 | const char *buf, size_t size); 37 | Tagger *createTagger() const; 38 | const char* what() { return what_.str(); } 39 | 40 | unsigned int nbest() const { return nbest_; } 41 | unsigned int vlevel() const { return vlevel_; } 42 | FeatureIndex *feature_index() const { return feature_index_.get(); } 43 | const char *getTemplate() const; 44 | 45 | private: 46 | bool open(const Param ¶m); 47 | bool openFromArray(const Param ¶m, 48 | const char *buf, size_t size); 49 | 50 | whatlog what_; 51 | unsigned int nbest_; 52 | unsigned int vlevel_; 53 | scoped_ptr feature_index_; 54 | }; 55 | 56 | class TaggerImpl : public Tagger { 57 | public: 58 | explicit TaggerImpl() : mode_(TEST), vlevel_(0), nbest_(0), 59 | ysize_(0), Z_(0), feature_id_(0), 60 | thread_id_(0), feature_index_(0), 61 | allocator_(0) {} 62 | virtual ~TaggerImpl() { close(); } 63 | 64 | Allocator *allocator() const { 65 | return allocator_; 66 | } 67 | 68 | void set_feature_id(size_t id) { feature_id_ = id; } 69 | size_t feature_id() const { return feature_id_; } 70 | void set_thread_id(unsigned short id) { thread_id_ = id; } 71 | unsigned short thread_id() const { return thread_id_; } 72 | Node *node(size_t i, size_t j) const { return node_[i][j]; } 73 | void set_node(Node *n, size_t i, size_t j) { node_[i][j] = n; } 74 | 75 | // for LEARN mode 76 | bool open(FeatureIndex *feature_index, Allocator *allocator); 77 | 78 | // for TEST mode, but feature_index is shared. 79 | bool open(FeatureIndex *feature_index, 80 | unsigned int nvest, unsigned velvel); 81 | 82 | // for TEST mode 83 | bool open(const Param ¶m); 84 | bool open(const char *argv); 85 | bool open(int argc, char **argv); 86 | 87 | bool set_model(const Model &model); 88 | 89 | 90 | int eval(); 91 | double gradient(double *); 92 | double collins(double *); 93 | bool shrink(); 94 | bool parse_stream(std::istream *is, std::ostream *os); 95 | bool read(std::istream *is); 96 | void close(); 97 | bool add(size_t size, const char **line); 98 | bool add(const char*); 99 | size_t size() const { return x_.size(); } 100 | size_t xsize() const { return feature_index_->xsize(); } 101 | size_t dsize() const { return feature_index_->size(); } 102 | const float *weight_vector() const { return feature_index_->alpha_float(); } 103 | bool empty() const { return x_.empty(); } 104 | size_t ysize() const { return ysize_; } 105 | double cost() const { return cost_; } 106 | double Z() const { return Z_; } 107 | double prob() const { return std::exp(- cost_ - Z_); } 108 | double prob(size_t i, size_t j) const { 109 | return toprob(node_[i][j], Z_); 110 | } 111 | double prob(size_t i) const { 112 | return toprob(node_[i][result_[i]], Z_); 113 | } 114 | void set_penalty(size_t i, size_t j, double penalty); 115 | double penalty(size_t i, size_t j) const; 116 | double alpha(size_t i, size_t j) const { return node_[i][j]->alpha; } 117 | double beta(size_t i, size_t j) const { return node_[i][j]->beta; } 118 | double emission_cost(size_t i, size_t j) const { return node_[i][j]->cost; } 119 | double next_transition_cost(size_t i, size_t j, size_t k) const { 120 | return node_[i][j]->rpath[k]->cost; 121 | } 122 | double prev_transition_cost(size_t i, size_t j, size_t k) const { 123 | return node_[i][j]->lpath[k]->cost; 124 | } 125 | double best_cost(size_t i, size_t j) const { 126 | return node_[i][j]->bestCost; 127 | } 128 | const int *emission_vector(size_t i, size_t j) const { 129 | return const_cast(node_[i][j]->fvector); 130 | } 131 | const int* next_transition_vector(size_t i, size_t j, size_t k) const { 132 | return node_[i][j]->rpath[k]->fvector; 133 | } 134 | const int* prev_transition_vector(size_t i, size_t j, size_t k) const { 135 | return node_[i][j]->lpath[k]->fvector; 136 | } 137 | size_t answer(size_t i) const { return answer_[i]; } 138 | size_t result(size_t i) const { return result_[i]; } 139 | size_t y(size_t i) const { return result_[i]; } 140 | const char* yname(size_t i) const { return feature_index_->y(i); } 141 | const char* y2(size_t i) const { return yname(result_[i]); } 142 | const char* x(size_t i, size_t j) const { return x_[i][j]; } 143 | const char** x(size_t i) const { 144 | return const_cast(&x_[i][0]); 145 | } 146 | const char* toString(); 147 | const char* toString(char *, size_t); 148 | const char* parse(const char*); 149 | const char* parse(const char*, size_t); 150 | const char* parse(const char*, size_t, char*, size_t); 151 | bool parse(); 152 | bool clear(); 153 | bool next(); 154 | 155 | unsigned int vlevel() const { return vlevel_; } 156 | 157 | float cost_factor() const { 158 | return feature_index_ ? feature_index_->cost_factor() : 0.0; 159 | } 160 | 161 | size_t nbest() const { return nbest_; } 162 | 163 | void set_vlevel(unsigned int vlevel) { 164 | vlevel_ = vlevel; 165 | } 166 | 167 | void set_cost_factor(float cost_factor) { 168 | if (cost_factor > 0 && feature_index_) { 169 | feature_index_->set_cost_factor(cost_factor); 170 | } 171 | } 172 | 173 | void set_nbest(size_t nbest) { 174 | nbest_ = nbest; 175 | } 176 | 177 | const char* what() { return what_.str(); } 178 | 179 | private: 180 | void forwardbackward(); 181 | void viterbi(); 182 | void buildLattice(); 183 | bool initNbest(); 184 | bool add2(size_t, const char **, bool); 185 | 186 | struct QueueElement { 187 | Node *node; 188 | QueueElement *next; 189 | double fx; 190 | double gx; 191 | }; 192 | 193 | class QueueElementComp { 194 | public: 195 | const bool operator()(QueueElement *q1, 196 | QueueElement *q2) 197 | { return(q1->fx > q2->fx); } 198 | }; 199 | 200 | enum { TEST, TEST_SHARED, LEARN }; 201 | unsigned int mode_ ; 202 | unsigned int vlevel_; 203 | unsigned int nbest_; 204 | size_t ysize_; 205 | double cost_; 206 | double Z_; 207 | size_t feature_id_; 208 | unsigned short thread_id_; 209 | FeatureIndex *feature_index_; 210 | Allocator *allocator_; 211 | std::vector > x_; 212 | std::vector > node_; 213 | std::vector > penalty_; 214 | std::vector answer_; 215 | std::vector result_; 216 | whatlog what_; 217 | string_buffer os_; 218 | 219 | scoped_ptr, 220 | QueueElementComp> > agenda_; 221 | scoped_ptr > nbest_freelist_; 222 | }; 223 | } 224 | #endif 225 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Basic Installation 2 | ================== 3 | 4 | These are generic installation instructions. 5 | 6 | The `configure' shell script attempts to guess correct values for 7 | various system-dependent variables used during compilation. It uses 8 | those values to create a `Makefile' in each directory of the package. 9 | It may also create one or more `.h' files containing system-dependent 10 | definitions. Finally, it creates a shell script `config.status' that 11 | you can run in the future to recreate the current configuration, a file 12 | `config.cache' that saves the results of its tests to speed up 13 | reconfiguring, and a file `config.log' containing compiler output 14 | (useful mainly for debugging `configure'). 15 | 16 | If you need to do unusual things to compile the package, please try 17 | to figure out how `configure' could check whether to do them, and mail 18 | diffs or instructions to the address given in the `README' so they can 19 | be considered for the next release. If at some point `config.cache' 20 | contains results you don't want to keep, you may remove or edit it. 21 | 22 | The file `configure.in' is used to create `configure' by a program 23 | called `autoconf'. You only need `configure.in' if you want to change 24 | it or regenerate `configure' using a newer version of `autoconf'. 25 | 26 | The simplest way to compile this package is: 27 | 28 | 1. `cd' to the directory containing the package's source code and type 29 | `./configure' to configure the package for your system. If you're 30 | using `csh' on an old version of System V, you might need to type 31 | `sh ./configure' instead to prevent `csh' from trying to execute 32 | `configure' itself. 33 | 34 | Running `configure' takes awhile. While running, it prints some 35 | messages telling which features it is checking for. 36 | 37 | 2. Type `make' to compile the package. 38 | 39 | 3. Optionally, type `make check' to run any self-tests that come with 40 | the package. 41 | 42 | 4. Type `make install' to install the programs and any data files and 43 | documentation. 44 | 45 | 5. You can remove the program binaries and object files from the 46 | source code directory by typing `make clean'. To also remove the 47 | files that `configure' created (so you can compile the package for 48 | a different kind of computer), type `make distclean'. There is 49 | also a `make maintainer-clean' target, but that is intended mainly 50 | for the package's developers. If you use it, you may have to get 51 | all sorts of other programs in order to regenerate files that came 52 | with the distribution. 53 | 54 | Compilers and Options 55 | ===================== 56 | 57 | Some systems require unusual options for compilation or linking that 58 | the `configure' script does not know about. You can give `configure' 59 | initial values for variables by setting them in the environment. Using 60 | a Bourne-compatible shell, you can do that on the command line like 61 | this: 62 | CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure 63 | 64 | Or on systems that have the `env' program, you can do it like this: 65 | env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure 66 | 67 | Compiling For Multiple Architectures 68 | ==================================== 69 | 70 | You can compile the package for more than one kind of computer at the 71 | same time, by placing the object files for each architecture in their 72 | own directory. To do this, you must use a version of `make' that 73 | supports the `VPATH' variable, such as GNU `make'. `cd' to the 74 | directory where you want the object files and executables to go and run 75 | the `configure' script. `configure' automatically checks for the 76 | source code in the directory that `configure' is in and in `..'. 77 | 78 | If you have to use a `make' that does not supports the `VPATH' 79 | variable, you have to compile the package for one architecture at a time 80 | in the source code directory. After you have installed the package for 81 | one architecture, use `make distclean' before reconfiguring for another 82 | architecture. 83 | 84 | Installation Names 85 | ================== 86 | 87 | By default, `make install' will install the package's files in 88 | `/usr/local/bin', `/usr/local/man', etc. You can specify an 89 | installation prefix other than `/usr/local' by giving `configure' the 90 | option `--prefix=PATH'. 91 | 92 | You can specify separate installation prefixes for 93 | architecture-specific files and architecture-independent files. If you 94 | give `configure' the option `--exec-prefix=PATH', the package will use 95 | PATH as the prefix for installing programs and libraries. 96 | Documentation and other data files will still use the regular prefix. 97 | 98 | In addition, if you use an unusual directory layout you can give 99 | options like `--bindir=PATH' to specify different values for particular 100 | kinds of files. Run `configure --help' for a list of the directories 101 | you can set and what kinds of files go in them. 102 | 103 | If the package supports it, you can cause programs to be installed 104 | with an extra prefix or suffix on their names by giving `configure' the 105 | option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. 106 | 107 | Optional Features 108 | ================= 109 | 110 | Some packages pay attention to `--enable-FEATURE' options to 111 | `configure', where FEATURE indicates an optional part of the package. 112 | They may also pay attention to `--with-PACKAGE' options, where PACKAGE 113 | is something like `gnu-as' or `x' (for the X Window System). The 114 | `README' should mention any `--enable-' and `--with-' options that the 115 | package recognizes. 116 | 117 | For packages that use the X Window System, `configure' can usually 118 | find the X include and library files automatically, but if it doesn't, 119 | you can use the `configure' options `--x-includes=DIR' and 120 | `--x-libraries=DIR' to specify their locations. 121 | 122 | Specifying the System Type 123 | ========================== 124 | 125 | There may be some features `configure' can not figure out 126 | automatically, but needs to determine by the type of host the package 127 | will run on. Usually `configure' can figure that out, but if it prints 128 | a message saying it can not guess the host type, give it the 129 | `--host=TYPE' option. TYPE can either be a short name for the system 130 | type, such as `sun4', or a canonical name with three fields: 131 | CPU-COMPANY-SYSTEM 132 | 133 | See the file `config.sub' for the possible values of each field. If 134 | `config.sub' isn't included in this package, then this package doesn't 135 | need to know the host type. 136 | 137 | If you are building compiler tools for cross-compiling, you can also 138 | use the `--target=TYPE' option to select the type of system they will 139 | produce code for and the `--build=TYPE' option to select the type of 140 | system on which you are compiling the package. 141 | 142 | Sharing Defaults 143 | ================ 144 | 145 | If you want to set default values for `configure' scripts to share, 146 | you can create a site shell script called `config.site' that gives 147 | default values for variables like `CC', `cache_file', and `prefix'. 148 | `configure' looks for `PREFIX/share/config.site' if it exists, then 149 | `PREFIX/etc/config.site' if it exists. Or, you can set the 150 | `CONFIG_SITE' environment variable to the location of the site script. 151 | A warning: not all `configure' scripts look for a site script. 152 | 153 | Operation Controls 154 | ================== 155 | 156 | `configure' recognizes the following options to control how it 157 | operates. 158 | 159 | `--cache-file=FILE' 160 | Use and save the results of the tests in FILE instead of 161 | `./config.cache'. Set FILE to `/dev/null' to disable caching, for 162 | debugging `configure'. 163 | 164 | `--help' 165 | Print a summary of the options to `configure', and exit. 166 | 167 | `--quiet' 168 | `--silent' 169 | `-q' 170 | Do not print messages saying which checks are being made. To 171 | suppress all normal output, redirect it to `/dev/null' (any error 172 | messages will still be shown). 173 | 174 | `--srcdir=DIR' 175 | Look for the package's source code in directory DIR. Usually 176 | `configure' can determine that directory automatically. 177 | 178 | `--version' 179 | Print the version of Autoconf used to generate the `configure' 180 | script, and exit. 181 | 182 | `configure' also accepts some other, not widely useful, options. 183 | -------------------------------------------------------------------------------- /googlecode_upload.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2006, 2007 Google Inc. All Rights Reserved. 4 | # Author: danderson@google.com (David Anderson) 5 | # 6 | # Script for uploading files to a Google Code project. 7 | # 8 | # This is intended to be both a useful script for people who want to 9 | # streamline project uploads and a reference implementation for 10 | # uploading files to Google Code projects. 11 | # 12 | # To upload a file to Google Code, you need to provide a path to the 13 | # file on your local machine, a small summary of what the file is, a 14 | # project name, and a valid account that is a member or owner of that 15 | # project. You can optionally provide a list of labels that apply to 16 | # the file. The file will be uploaded under the same name that it has 17 | # in your local filesystem (that is, the "basename" or last path 18 | # component). Run the script with '--help' to get the exact syntax 19 | # and available options. 20 | # 21 | # Note that the upload script requests that you enter your 22 | # googlecode.com password. This is NOT your Gmail account password! 23 | # This is the password you use on googlecode.com for committing to 24 | # Subversion and uploading files. You can find your password by going 25 | # to http://code.google.com/hosting/settings when logged in with your 26 | # Gmail account. If you have already committed to your project's 27 | # Subversion repository, the script will automatically retrieve your 28 | # credentials from there (unless disabled, see the output of '--help' 29 | # for details). 30 | # 31 | # If you are looking at this script as a reference for implementing 32 | # your own Google Code file uploader, then you should take a look at 33 | # the upload() function, which is the meat of the uploader. You 34 | # basically need to build a multipart/form-data POST request with the 35 | # right fields and send it to https://PROJECT.googlecode.com/files . 36 | # Authenticate the request using HTTP Basic authentication, as is 37 | # shown below. 38 | # 39 | # Licensed under the terms of the Apache Software License 2.0: 40 | # http://www.apache.org/licenses/LICENSE-2.0 41 | # 42 | # Questions, comments, feature requests and patches are most welcome. 43 | # Please direct all of these to the Google Code users group: 44 | # http://groups.google.com/group/google-code-hosting 45 | 46 | """Google Code file uploader script. 47 | """ 48 | 49 | __author__ = 'danderson@google.com (David Anderson)' 50 | 51 | import httplib 52 | import os.path 53 | import optparse 54 | import getpass 55 | import base64 56 | import sys 57 | 58 | 59 | def upload(file, project_name, user_name, password, summary, labels=None): 60 | """Upload a file to a Google Code project's file server. 61 | 62 | Args: 63 | file: The local path to the file. 64 | project_name: The name of your project on Google Code. 65 | user_name: Your Google account name. 66 | password: The googlecode.com password for your account. 67 | Note that this is NOT your global Google Account password! 68 | summary: A small description for the file. 69 | labels: an optional list of label strings with which to tag the file. 70 | 71 | Returns: a tuple: 72 | http_status: 201 if the upload succeeded, something else if an 73 | error occured. 74 | http_reason: The human-readable string associated with http_status 75 | file_url: If the upload succeeded, the URL of the file on Google 76 | Code, None otherwise. 77 | """ 78 | # The login is the user part of user@gmail.com. If the login provided 79 | # is in the full user@domain form, strip it down. 80 | if user_name.endswith('@gmail.com'): 81 | user_name = user_name[:user_name.index('@gmail.com')] 82 | 83 | form_fields = [('summary', summary)] 84 | if labels is not None: 85 | form_fields.extend([('label', l.strip()) for l in labels]) 86 | 87 | content_type, body = encode_upload_request(form_fields, file) 88 | 89 | upload_host = '%s.googlecode.com' % project_name 90 | upload_uri = '/files' 91 | auth_token = base64.b64encode('%s:%s'% (user_name, password)) 92 | headers = { 93 | 'Authorization': 'Basic %s' % auth_token, 94 | 'User-Agent': 'Googlecode.com uploader v0.9.4', 95 | 'Content-Type': content_type, 96 | } 97 | 98 | server = httplib.HTTPSConnection(upload_host) 99 | server.request('POST', upload_uri, body, headers) 100 | resp = server.getresponse() 101 | server.close() 102 | 103 | if resp.status == 201: 104 | location = resp.getheader('Location', None) 105 | else: 106 | location = None 107 | return resp.status, resp.reason, location 108 | 109 | 110 | def encode_upload_request(fields, file_path): 111 | """Encode the given fields and file into a multipart form body. 112 | 113 | fields is a sequence of (name, value) pairs. file is the path of 114 | the file to upload. The file will be uploaded to Google Code with 115 | the same file name. 116 | 117 | Returns: (content_type, body) ready for httplib.HTTP instance 118 | """ 119 | BOUNDARY = '----------Googlecode_boundary_reindeer_flotilla' 120 | CRLF = '\r\n' 121 | 122 | body = [] 123 | 124 | # Add the metadata about the upload first 125 | for key, value in fields: 126 | body.extend( 127 | ['--' + BOUNDARY, 128 | 'Content-Disposition: form-data; name="%s"' % key, 129 | '', 130 | value, 131 | ]) 132 | 133 | # Now add the file itself 134 | file_name = os.path.basename(file_path) 135 | f = open(file_path, 'rb') 136 | file_content = f.read() 137 | f.close() 138 | 139 | body.extend( 140 | ['--' + BOUNDARY, 141 | 'Content-Disposition: form-data; name="filename"; filename="%s"' 142 | % file_name, 143 | # The upload server determines the mime-type, no need to set it. 144 | 'Content-Type: application/octet-stream', 145 | '', 146 | file_content, 147 | ]) 148 | 149 | # Finalize the form body 150 | body.extend(['--' + BOUNDARY + '--', '']) 151 | 152 | return 'multipart/form-data; boundary=%s' % BOUNDARY, CRLF.join(body) 153 | 154 | 155 | def upload_find_auth(file_path, project_name, summary, labels=None, 156 | user_name=None, password=None, tries=3): 157 | """Find credentials and upload a file to a Google Code project's file server. 158 | 159 | file_path, project_name, summary, and labels are passed as-is to upload. 160 | 161 | Args: 162 | file_path: The local path to the file. 163 | project_name: The name of your project on Google Code. 164 | summary: A small description for the file. 165 | labels: an optional list of label strings with which to tag the file. 166 | config_dir: Path to Subversion configuration directory, 'none', or None. 167 | user_name: Your Google account name. 168 | tries: How many attempts to make. 169 | """ 170 | 171 | while tries > 0: 172 | if user_name is None: 173 | # Read username if not specified or loaded from svn config, or on 174 | # subsequent tries. 175 | sys.stdout.write('Please enter your googlecode.com username: ') 176 | sys.stdout.flush() 177 | user_name = sys.stdin.readline().rstrip() 178 | if password is None: 179 | # Read password if not loaded from svn config, or on subsequent tries. 180 | print 'Please enter your googlecode.com password.' 181 | print '** Note that this is NOT your Gmail account password! **' 182 | print 'It is the password you use to access Subversion repositories,' 183 | print 'and can be found here: http://code.google.com/hosting/settings' 184 | password = getpass.getpass() 185 | 186 | status, reason, url = upload(file_path, project_name, user_name, password, 187 | summary, labels) 188 | # Returns 403 Forbidden instead of 401 Unauthorized for bad 189 | # credentials as of 2007-07-17. 190 | if status in [httplib.FORBIDDEN, httplib.UNAUTHORIZED]: 191 | # Rest for another try. 192 | user_name = password = None 193 | tries = tries - 1 194 | else: 195 | # We're done. 196 | break 197 | 198 | return status, reason, url 199 | 200 | 201 | def main(): 202 | parser = optparse.OptionParser(usage='googlecode-upload.py -s SUMMARY ' 203 | '-p PROJECT [options] FILE') 204 | parser.add_option('-s', '--summary', dest='summary', 205 | help='Short description of the file') 206 | parser.add_option('-p', '--project', dest='project', 207 | help='Google Code project name') 208 | parser.add_option('-u', '--user', dest='user', 209 | help='Your Google Code username') 210 | parser.add_option('-w', '--password', dest='password', 211 | help='Your Google Code password') 212 | parser.add_option('-l', '--labels', dest='labels', 213 | help='An optional list of comma-separated labels to attach ' 214 | 'to the file') 215 | 216 | options, args = parser.parse_args() 217 | 218 | if not options.summary: 219 | parser.error('File summary is missing.') 220 | elif not options.project: 221 | parser.error('Project name is missing.') 222 | elif len(args) < 1: 223 | parser.error('File to upload not provided.') 224 | elif len(args) > 1: 225 | parser.error('Only one file may be specified.') 226 | 227 | file_path = args[0] 228 | 229 | if options.labels: 230 | labels = options.labels.split(',') 231 | else: 232 | labels = None 233 | 234 | status, reason, url = upload_find_auth(file_path, options.project, 235 | options.summary, labels, 236 | options.user, options.password) 237 | if url: 238 | print 'The file was uploaded successfully.' 239 | print 'URL: %s' % url 240 | return 0 241 | else: 242 | print 'An error occurred. Your file was not uploaded.' 243 | print 'Google Code upload server said: %s (%s)' % (reason, status) 244 | return 1 245 | 246 | 247 | if __name__ == '__main__': 248 | sys.exit(main()) 249 | -------------------------------------------------------------------------------- /doxygen/globals_func.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | CRF++: File Members 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
CRF++ 26 | 27 |
28 | 29 |
36 |
37 | 38 | 39 | 47 | 53 | 61 | 66 |
67 |
68 |   69 | 70 |

- c -

    71 |
  • crfpp_add() 72 | : crfpp.h 73 |
  • 74 |
  • crfpp_add2() 75 | : crfpp.h 76 |
  • 77 |
  • crfpp_alpha() 78 | : crfpp.h 79 |
  • 80 |
  • crfpp_answer() 81 | : crfpp.h 82 |
  • 83 |
  • crfpp_best_cost() 84 | : crfpp.h 85 |
  • 86 |
  • crfpp_beta() 87 | : crfpp.h 88 |
  • 89 |
  • crfpp_clear() 90 | : crfpp.h 91 |
  • 92 |
  • crfpp_cost_factor() 93 | : crfpp.h 94 |
  • 95 |
  • crfpp_destroy() 96 | : crfpp.h 97 |
  • 98 |
  • crfpp_dsize() 99 | : crfpp.h 100 |
  • 101 |
  • crfpp_emisstion_cost() 102 | : crfpp.h 103 |
  • 104 |
  • crfpp_emittion_vector() 105 | : crfpp.h 106 |
  • 107 |
  • crfpp_empty() 108 | : crfpp.h 109 |
  • 110 |
  • crfpp_learn() 111 | : crfpp.h 112 |
  • 113 |
  • crfpp_learn2() 114 | : crfpp.h 115 |
  • 116 |
  • crfpp_model_destroy() 117 | : crfpp.h 118 |
  • 119 |
  • crfpp_model_from_array_new() 120 | : crfpp.h 121 |
  • 122 |
  • crfpp_model_from_array_new2() 123 | : crfpp.h 124 |
  • 125 |
  • crfpp_model_get_template() 126 | : crfpp.h 127 |
  • 128 |
  • crfpp_model_new() 129 | : crfpp.h 130 |
  • 131 |
  • crfpp_model_new2() 132 | : crfpp.h 133 |
  • 134 |
  • crfpp_model_new_tagger() 135 | : crfpp.h 136 |
  • 137 |
  • crfpp_model_strerror() 138 | : crfpp.h 139 |
  • 140 |
  • crfpp_new() 141 | : crfpp.h 142 |
  • 143 |
  • crfpp_new2() 144 | : crfpp.h 145 |
  • 146 |
  • crfpp_next() 147 | : crfpp.h 148 |
  • 149 |
  • crfpp_next_transition_cost() 150 | : crfpp.h 151 |
  • 152 |
  • crfpp_next_transition_vector() 153 | : crfpp.h 154 |
  • 155 |
  • crfpp_parse() 156 | : crfpp.h 157 |
  • 158 |
  • crfpp_parse_tostr() 159 | : crfpp.h 160 |
  • 161 |
  • crfpp_parse_tostr2() 162 | : crfpp.h 163 |
  • 164 |
  • crfpp_parse_tostr3() 165 | : crfpp.h 166 |
  • 167 |
  • crfpp_penalty() 168 | : crfpp.h 169 |
  • 170 |
  • crfpp_prev_transition_cost() 171 | : crfpp.h 172 |
  • 173 |
  • crfpp_prev_transition_vector() 174 | : crfpp.h 175 |
  • 176 |
  • crfpp_prob() 177 | : crfpp.h 178 |
  • 179 |
  • crfpp_prob2() 180 | : crfpp.h 181 |
  • 182 |
  • crfpp_prob3() 183 | : crfpp.h 184 |
  • 185 |
  • crfpp_result() 186 | : crfpp.h 187 |
  • 188 |
  • crfpp_set_cost_factor() 189 | : crfpp.h 190 |
  • 191 |
  • crfpp_set_model() 192 | : crfpp.h 193 |
  • 194 |
  • crfpp_set_nbest() 195 | : crfpp.h 196 |
  • 197 |
  • crfpp_set_penalty() 198 | : crfpp.h 199 |
  • 200 |
  • crfpp_set_vlevel() 201 | : crfpp.h 202 |
  • 203 |
  • crfpp_size() 204 | : crfpp.h 205 |
  • 206 |
  • crfpp_strerror() 207 | : crfpp.h 208 |
  • 209 |
  • crfpp_test() 210 | : crfpp.h 211 |
  • 212 |
  • crfpp_test2() 213 | : crfpp.h 214 |
  • 215 |
  • crfpp_tostr() 216 | : crfpp.h 217 |
  • 218 |
  • crfpp_tostr2() 219 | : crfpp.h 220 |
  • 221 |
  • crfpp_vlevel() 222 | : crfpp.h 223 |
  • 224 |
  • crfpp_weight_vector() 225 | : crfpp.h 226 |
  • 227 |
  • crfpp_x() 228 | : crfpp.h 229 |
  • 230 |
  • crfpp_x2() 231 | : crfpp.h 232 |
  • 233 |
  • crfpp_xsize() 234 | : crfpp.h 235 |
  • 236 |
  • crfpp_y() 237 | : crfpp.h 238 |
  • 239 |
  • crfpp_y2() 240 | : crfpp.h 241 |
  • 242 |
  • crfpp_yname() 243 | : crfpp.h 244 |
  • 245 |
  • crfpp_ysize() 246 | : crfpp.h 247 |
  • 248 |
  • crfpp_Z() 249 | : crfpp.h 250 |
  • 251 |
252 |
253 | 254 | 255 | 260 | 261 | 262 | 263 | -------------------------------------------------------------------------------- /doxygen/globals.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | CRF++: File Members 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
CRF++ 26 | 27 |
28 | 29 |
36 |
37 | 38 | 39 | 47 | 53 | 61 | 66 |
67 |
68 |
Here is a list of all file members with links to the files they belong to:
69 | 70 |

- c -

    71 |
  • crfpp_add() 72 | : crfpp.h 73 |
  • 74 |
  • crfpp_add2() 75 | : crfpp.h 76 |
  • 77 |
  • crfpp_alpha() 78 | : crfpp.h 79 |
  • 80 |
  • crfpp_answer() 81 | : crfpp.h 82 |
  • 83 |
  • crfpp_best_cost() 84 | : crfpp.h 85 |
  • 86 |
  • crfpp_beta() 87 | : crfpp.h 88 |
  • 89 |
  • crfpp_clear() 90 | : crfpp.h 91 |
  • 92 |
  • crfpp_cost_factor() 93 | : crfpp.h 94 |
  • 95 |
  • crfpp_destroy() 96 | : crfpp.h 97 |
  • 98 |
  • CRFPP_DLL_CLASS_EXTERN 99 | : crfpp.h 100 |
  • 101 |
  • CRFPP_DLL_EXTERN 102 | : crfpp.h 103 |
  • 104 |
  • crfpp_dsize() 105 | : crfpp.h 106 |
  • 107 |
  • crfpp_emisstion_cost() 108 | : crfpp.h 109 |
  • 110 |
  • crfpp_emittion_vector() 111 | : crfpp.h 112 |
  • 113 |
  • crfpp_empty() 114 | : crfpp.h 115 |
  • 116 |
  • crfpp_learn() 117 | : crfpp.h 118 |
  • 119 |
  • crfpp_learn2() 120 | : crfpp.h 121 |
  • 122 |
  • crfpp_model_destroy() 123 | : crfpp.h 124 |
  • 125 |
  • crfpp_model_from_array_new() 126 | : crfpp.h 127 |
  • 128 |
  • crfpp_model_from_array_new2() 129 | : crfpp.h 130 |
  • 131 |
  • crfpp_model_get_template() 132 | : crfpp.h 133 |
  • 134 |
  • crfpp_model_new() 135 | : crfpp.h 136 |
  • 137 |
  • crfpp_model_new2() 138 | : crfpp.h 139 |
  • 140 |
  • crfpp_model_new_tagger() 141 | : crfpp.h 142 |
  • 143 |
  • crfpp_model_strerror() 144 | : crfpp.h 145 |
  • 146 |
  • crfpp_model_t 147 | : crfpp.h 148 |
  • 149 |
  • crfpp_new() 150 | : crfpp.h 151 |
  • 152 |
  • crfpp_new2() 153 | : crfpp.h 154 |
  • 155 |
  • crfpp_next() 156 | : crfpp.h 157 |
  • 158 |
  • crfpp_next_transition_cost() 159 | : crfpp.h 160 |
  • 161 |
  • crfpp_next_transition_vector() 162 | : crfpp.h 163 |
  • 164 |
  • crfpp_parse() 165 | : crfpp.h 166 |
  • 167 |
  • crfpp_parse_tostr() 168 | : crfpp.h 169 |
  • 170 |
  • crfpp_parse_tostr2() 171 | : crfpp.h 172 |
  • 173 |
  • crfpp_parse_tostr3() 174 | : crfpp.h 175 |
  • 176 |
  • crfpp_penalty() 177 | : crfpp.h 178 |
  • 179 |
  • crfpp_prev_transition_cost() 180 | : crfpp.h 181 |
  • 182 |
  • crfpp_prev_transition_vector() 183 | : crfpp.h 184 |
  • 185 |
  • crfpp_prob() 186 | : crfpp.h 187 |
  • 188 |
  • crfpp_prob2() 189 | : crfpp.h 190 |
  • 191 |
  • crfpp_prob3() 192 | : crfpp.h 193 |
  • 194 |
  • crfpp_result() 195 | : crfpp.h 196 |
  • 197 |
  • crfpp_set_cost_factor() 198 | : crfpp.h 199 |
  • 200 |
  • crfpp_set_model() 201 | : crfpp.h 202 |
  • 203 |
  • crfpp_set_nbest() 204 | : crfpp.h 205 |
  • 206 |
  • crfpp_set_penalty() 207 | : crfpp.h 208 |
  • 209 |
  • crfpp_set_vlevel() 210 | : crfpp.h 211 |
  • 212 |
  • crfpp_size() 213 | : crfpp.h 214 |
  • 215 |
  • crfpp_strerror() 216 | : crfpp.h 217 |
  • 218 |
  • crfpp_t 219 | : crfpp.h 220 |
  • 221 |
  • crfpp_test() 222 | : crfpp.h 223 |
  • 224 |
  • crfpp_test2() 225 | : crfpp.h 226 |
  • 227 |
  • crfpp_tostr() 228 | : crfpp.h 229 |
  • 230 |
  • crfpp_tostr2() 231 | : crfpp.h 232 |
  • 233 |
  • crfpp_vlevel() 234 | : crfpp.h 235 |
  • 236 |
  • crfpp_weight_vector() 237 | : crfpp.h 238 |
  • 239 |
  • crfpp_x() 240 | : crfpp.h 241 |
  • 242 |
  • crfpp_x2() 243 | : crfpp.h 244 |
  • 245 |
  • crfpp_xsize() 246 | : crfpp.h 247 |
  • 248 |
  • crfpp_y() 249 | : crfpp.h 250 |
  • 251 |
  • crfpp_y2() 252 | : crfpp.h 253 |
  • 254 |
  • crfpp_yname() 255 | : crfpp.h 256 |
  • 257 |
  • crfpp_ysize() 258 | : crfpp.h 259 |
  • 260 |
  • crfpp_Z() 261 | : crfpp.h 262 |
  • 263 |
264 |
265 | 266 | 267 | 272 | 273 | 274 | 275 | -------------------------------------------------------------------------------- /doxygen/functions_func.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | CRF++: Class Members - Functions 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
CRF++ 26 | 27 |
28 | 29 |
36 |
37 | 38 | 39 | 47 | 53 | 59 | 81 |
82 |
83 |   84 | 85 |

- a -

96 | 97 | 98 |

- b -

106 | 107 | 108 |

- c -

122 | 123 | 124 |

- d -

129 | 130 | 131 |

- e -

142 | 143 | 144 |

- g -

149 | 150 | 151 |

- n -

165 | 166 | 167 |

- o -

176 | 177 | 178 |

- p -

195 | 196 | 197 |

- r -

202 | 203 | 204 |

- s -

224 | 225 | 226 |

- t -

231 | 232 | 233 |

- v -

238 | 239 | 240 |

- w -

249 | 250 | 251 |

- x -

259 | 260 | 261 |

- y -

275 | 276 | 277 |

- z -

282 | 283 | 284 |

- ~ -

292 |
293 | 294 | 295 | 300 | 301 | 302 | 303 | --------------------------------------------------------------------------------