Blame view

morfeusz/test/test_recognize_dict.cpp 1.55 KB
Michał Lenart authored
1
2
3
4
5
6
7
8
9
10
11
/* 
 * File:   test_morph.cpp
 * Author: mlenart
 *
 * Created on November 8, 2013, 4:12 PM
 */

//#include <cstdlib>
#include <sstream>
#include <iostream>
#include "utils.hpp"
Michał Lenart authored
12
13
#include "MorfeuszInternal.hpp"
#include "morfeusz2.h"
Michał Lenart authored
14
15

using namespace std;
Michał Lenart authored
16
using namespace morfeusz;
Michał Lenart authored
17
18
19
20
21

int main(int argc, char** argv) {
    validate(argc == 3, "Must provide exactly 2 arguments - input FSA filename and dictionary filename.");
    string fsaFilename = argv[1];
    string dictFilename = argv[2];
Michał Lenart authored
22
    MorfeuszInternal morfeusz;
Michał Lenart authored
23
    morfeusz.setAnalyzerDictionary(fsaFilename);
Michał Lenart authored
24
25
    ifstream in;
    in.open(dictFilename.c_str());
Michał Lenart authored
26
27
28
29
30
31
32
33
34
35
    string line;
    while (getline(in, line)) {
        cerr << "TEST " << line << endl;
        vector<string> splitVector(split(line, '\t'));
        string orth = splitVector[0];
        string lemma = splitVector[1];
        string tag = splitVector[2];
        string name = splitVector[3];

        vector<MorphInterpretation> res;
Michał Lenart authored
36
        cerr << "ANALYZE '" << orth << "'" << endl;
Michał Lenart authored
37
38
39
        morfeusz.analyze(orth, res);
        bool found = false;
Michał Lenart authored
40
41
        for (unsigned int i = 0; i < res.size(); i++) {
            MorphInterpretation& mi = res[i];
Michał Lenart authored
42
43
44
45
46
47
48
49
50
51
            DEBUG("FOUND: " + mi.getLemma() + ":" + mi.getTag());
            if (lemma == mi.getLemma() && tag == mi.getTag() && name == mi.getName()) {
                DEBUG("RECOGNIZED " + orth + " " + lemma + ":" + tag + ":" + name);
                found = true;
            }
        }
        validate(found, "Failed to recognize " + orth + " " + lemma + ":" + tag + ":" + name);
    }
    return 0;
}