test_morfeusz.cpp
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* File: test_morfeusz.cpp
* Author: mlenart
*
* Created on 14 listopad 2013, 15:50
*/
#include <cstdlib>
#include <cstdio>
#include <sstream>
#include <iostream>
#include "Morfeusz.hpp"
using namespace std;
void debug(const MorphInterpretation& interp) {
fprintf(stderr,
"%d %d %s %s %s %s\n",
interp.getStartNode(), interp.getEndNode(),
interp.getOrth().c_str(), interp.getLemma().c_str(),
interp.getTag().c_str(), interp.getName().c_str());
}
void doTest(
const Morfeusz& morfeusz,
const string& inputFilename) {
ifstream ifs;
// ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
ifs.open(inputFilename, ios::binary);
string line;
while (getline(ifs, line)) {
DEBUG(line);
vector<MorphInterpretation> res;
morfeusz.analyze(line, res);
for (MorphInterpretation& mi: res) {
debug(mi);
}
}
validate(ifs.eof(), "Failed to read the input file to the end");
}
int main(int argc, char** argv) {
validate(argc == 3, "Must provide exactly two arguments - FSA filename, and input filename.");
string fsaFilename = argv[1];
string inputFilename = argv[2];
DEBUG("FSA: "+fsaFilename);
DEBUG("input text: "+inputFilename);
Morfeusz morfeusz(fsaFilename);
doTest(morfeusz, inputFilename);
return 0;
}