NERsuite  1.1.1
src/nersuitetest/NERSuiteTest.h
00001 #ifndef _NERSUITE_TEST_H
00002 #define _NERSUITE_TEST_H
00003 
00004 #include <string>
00005 #include <sstream>
00006 #include <stdio.h>
00007 #include "TestUtil.h"
00008 #include "../nersuite/nersuite.h"
00009 #include "fext_helper.h"
00010 
00011 using namespace std;
00012 using namespace NER;
00013 
00014 void TestNERSuite_LearnArgs()
00015 {
00016         char* args[] = { "-m", "model.m" };
00017         Suite nersuite(2, args);
00018 }
00019 
00020 void TestNERSuite_TagArgs()
00021 {
00022         char* args[] = { "-m", "model.m" };
00023         Suite nersuite(2, args);
00024 }
00025 
00026 void TestNERSuite_Learn()
00027 {
00028         FILE* fp = fopen("tmp_learn.txt", "wt");
00029         fputs("B-TestTag        0       2       ABC     ABC     NN      O       O       O       O       O       O       O       O       O\n", fp);
00030         fputs("B-TestTag        3       5       DEF     DEF     NN      O       O       O       O       O       O       O       O       O\n", fp);
00031         fputs("B-TestTag        6       8       GHI     GHI     NN      O       O       O       O       O       O       O       O       O\n", fp);
00032         fclose(fp);
00033 
00034         extern string CRFSuiteDummyLog;
00035         CRFSuiteDummyLog.clear();
00036 
00037         char* args[] = { "-m", "model.m", "-f", "tmp_learn.txt" };
00038         Suite nersuite(4, args);
00039         if (nersuite.learn() != 0)
00040         {
00041                 throw new TestException("assert failed", __FILE__, __LINE__);
00042         }
00043 
00044         extern string CRFSuiteDummyLog;
00045         if (CRFSuiteDummyLog !=
00046                 "Trainer::Trainer;"
00047                 "Trainer::select(lbfgs,crf1d);"
00048                 "Trainer::params;"
00049                 "Trainer::set(c2,1.000000);"
00050                 "Trainer::append;"
00051                 "Trainer2::get_instance_num;"
00052                 "Trainer2::get_item_num;"
00053                 "Trainer2::get_label_num;"
00054                 "Trainer2::get_attribute_num;"
00055                 "Trainer::train(model.m,-1);"
00056                 "Trainer::~Trainer;")
00057         {
00058                 throw new TestException("assert failed", __FILE__, __LINE__);
00059         }
00060 }
00061 
00062 void TestNERSuite_Tag()
00063 {
00064         FILE* fp = fopen("tmp_tag.txt", "wt");
00065         fputs("0        2       ABC     ABC     NN      O       O       O       O       O       O       O       O       O\n", fp);
00066         fputs("3        5       DEF     DEF     NN      O       O       O       O       O       O       O       O       O\n", fp);
00067         fputs("6        8       GHI     GHI     NN      O       O       O       O       O       O       O       O       O\n", fp);
00068         fclose(fp);
00069 
00070         extern string CRFSuiteDummyLog;
00071         CRFSuiteDummyLog.clear();
00072 
00073         char* args[] = { "-m", "model.m", "-f", "tmp_tag.txt" };
00074         Suite nersuite(4, args);
00075         if (nersuite.tag() != 0)
00076         {
00077                 throw new TestException("assert failed", __FILE__, __LINE__);
00078         }
00079 
00080         if (CRFSuiteDummyLog !=
00081                 "Tagger::Tagger;"
00082                 "Tagger::open(model.m);"
00083                 "Tagger::labels;"
00084                 "Tagger::tag;"
00085                 "Tagger::~Tagger;"
00086 )
00087         {
00088                 throw new TestException("assert failed", __FILE__, __LINE__);
00089         }
00090 }
00091 
00092 #endif
 All Classes Functions Variables