Commit f1efa81a authored by Benoit Favre's avatar Benoit Favre
Browse files

make simple parser test more generic

parent 64eb310f
......@@ -95,6 +95,7 @@ macaon::Parser::Parser(
int argc = sizeof(argv) / sizeof(char*);
ctx = maca_graph_parser_LoadCTX(argc, (char**) argv);
ctx->verbose_flag = verbose_flag;
int i;
int sent_num;
......
#include<iostream>
#include"simple_parser.h"
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include "simple_parser.h"
using namespace macaon;
int main(int argc, char** argv)
{
// Parser mp("en", 3, "/home/alexis/test_maca_graph_parser/en/ptb.mod", "/home/alexis/test_maca_graph_parser/en/ptb.alpha", 1);
if(argc < 4) {
std::cerr << "usage: " << argv[0] << " <model.bin> <model.alpha> <model.dep_count>\n";
std::cerr << "usage: " << argv[0] << " <cfg> <model.bin> <model.alpha> <model.dep_count>\n";
std::cerr << "expects: one word, one lemma, one tag, per line, empty line between sentences\n";
return 1;
}
Parser mp("en", 3, argv[1], argv[2], argv[3], 1);
for(int iteration = 0; iteration < 10; iteration++) {
std::vector<std::string> words;
std::vector<std::string> lemmas;
std::vector<std::string> tags;
words.push_back("the");
words.push_back("boy");
words.push_back("hits");
words.push_back("the");
words.push_back("ball");
words.push_back(".");
lemmas.push_back("the");
lemmas.push_back("boy");
lemmas.push_back("hit");
lemmas.push_back("the");
lemmas.push_back("ball");
lemmas.push_back(".");
tags.push_back("DT");
tags.push_back("NN");
tags.push_back("VBZ");
tags.push_back("DT");
tags.push_back("NN");
tags.push_back(".");
Parser mp(argv[1], 0, argv[2], argv[3], argv[4], 1);
std::vector<ParsedWord> output;
std::vector<std::string> words;
std::vector<std::string> lemmas;
std::vector<std::string> tags;
mp.ProcessSentence(words, tags, lemmas, output);
//mp.ProcessSentence(words, tags, output);
for(size_t i = 0; i < output.size(); i++){
// std::cout << i << " " << output[i].word << " " << output[i].lemma << " " << output[i].posTag << " " << output[i].dependencyParent << " " << output[i].dependencyLabel << "\n";
std::cout << i << " " << output[i].word << " " << output[i].posTag << " " << output[i].dependencyParent << " " << output[i].dependencyLabel << "\n";
std::string line;
while(std::getline(std::cin, line)) {
std::cout << "|" << line << "|\n";
if(line == "") {
std::vector<ParsedWord> output;
mp.ProcessSentence(words, tags, lemmas, output);
std::cout << "size: " << output.size() << "\n";
for(size_t i = 0; i < output.size(); i++){
std::cout << i << " " << output[i].word << " " << output[i].posTag << " " << output[i].dependencyParent << " " << output[i].dependencyLabel << "\n";
}
std::cout << "\n";
words.clear();
tags.clear();
lemmas.clear();
}
std::stringstream reader(line);
std::string word, lemma, tag;
reader >> word >> lemma >> tag;
words.push_back(word);
lemmas.push_back(lemma);
tags.push_back(tag);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment