Programming
// FromTreeTagger
#include <iostream>
#include <fstream>
#include <string>
#include <boost/regex.hpp>
using namespace std;
using namespace boost;
int main(int arg, char *argv[]){
string input;
string output;
// char str[256]
string str;
if(arg < 2){
cout << "引数指定は" << endl;
cout << " FromTreeTagger inputfile outfile" << endl;
return -1;
}
else if (arg == 3){
input = argv[1];
output = argv[2];
}
else{
cout << "引数指定は" << endl;
cout << " FromTreeTagger inputfile outfile" << endl;
return -1;
}
ifstream ifs(input.c_str());// オリジナルファイルを開き
if(!ifs){
cout << "cant find file" << endl;
return -1;
}
else{
cout << "open " << input << endl;
}
ofstream ofs(output.c_str());
if(!ofs){
cout << "cant open file" << endl;
return -1;
}
regex reg("(\\S+)\\s+(\\S+)\\s+(\\S+|<unknown>)");
// 空白を挟んで三列
// const boost::regex regexp2("<unknown>"); // 空白を挟んで三列
smatch match;
// while(!ifs.eof()){
// ifs.getline(str, 256);
while(getline(ifs, str)){
// cout << str << endl;
if (regex_match(str, match, reg)) {
// cout << "一致しました\n";
if(match.str(3) == "<unknown>"){
// cout << "<unknown> を補足しました" << endl;
ofs << match.str(1) << endl;
}
else if(match.str(3) == "an"){
ofs << "a" << endl;
}
else {
ofs << match.str(3) << endl;
}
}
else{
cout << str << "はマッチしませんでした" << endl;
}
}
return 0;
}