#ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include "unicode.h" #include "grammar.h" #include "profile.h" #include "derivReader.h" #include "derivReader.cpp" using namespace std; void collectleaves(Grammar &g, tToken s, vector &ancestors, vector &leaves); void parse_options(int argc, char **argv, string *gfname, string *pname, int *parsenum); bool is_num(string str); int main (int argc, char **argv) { // setting option variables string gfname, pname; int parsenum; parse_options(argc, argv, &gfname, &pname, &parsenum); // UTF-8 encoder initialize_encoding_converter("utf-8"); Grammar g(gfname); Profile p(pname); vector leaves; //used in collectleaves() // ResultReader > reader(g, leaves, NULL, NULL, &collectleaves); DerivReader > reader(g, leaves, NULL, NULL, &collectleaves); pair,string> result = p.getResult(); int context = -1; // context is item id int event = -1; // event is parse id while (result.first.first >= 0) {//new item/context if (result.first.first != context) {//new item/context if (context != -1) { //finish last context }//finished last context } context = result.first.first; event = result.first.second; if (parsenum >= 0 && event != parsenum) { result = p.getResult(); continue; } //do stuff with result leaves.clear(); reader.readDeriv(result.second); result = p.getResult(); for(vector::iterator it = leaves.begin(); it != leaves.end(); ++it) { cout << it->surface() << "\t" << it->tag() << endl; } } //finish last context return 0; } void parse_options(int argc, char **argv, string *gfname, string *pname, int *parsenum) { namespace po = boost::program_options; po::options_description visible("Options"); visible.add_options() ("help,h", "This usage information.") ("analysis,a", po::value(parsenum)->default_value(-1), "Select a specific analysis, default (-1): all.") ; po::options_description hidden("Hidden options"); hidden.add_options() ("grammar-file", po::value(gfname), "grammar .tdl file") ("profile", po::value(pname), "profile") ; po::options_description cmd_line ("Command line options"); cmd_line.add(visible).add(hidden); po::positional_options_description p; p.add("grammar-file",1).add("profile",1); po::variables_map vm; po::store(po::command_line_parser(argc, argv). options(cmd_line).positional(p).run(), vm); notify(vm); if (vm.count("help")) { cout << "Usage: " << argv[0] << " [options] " << "grammar-file profile" << endl; cout << visible << endl; exit(0); } if (!vm.count("grammar-file") || !vm.count("profile")) { cerr << "Insufficient arguments given." << endl; cerr << "Usage: " << argv[0] << " [options] " << "grammar-file profile" << endl; cerr << visible << endl; exit(1); } } void collectleaves(Grammar &g, tToken s, vector &ancestors, vector &leaves) { leaves.push_back(s); string tag(ancestors.back().surface()); leaves.back().tag(tag); } bool is_num(string str) { if (str.empty()) return false; if (str.at(0) == '+' || str.at(0) == '-') str.erase(0,1); if (str.empty() || !isdigit(str.at(0))) return false; else str.erase(0,1); while (!str.empty() && isdigit(str.at(0))) str.erase(0,1); if (str.empty()) return true; if (str.at(0) == '.') { str.erase(0,1); if (str.empty()) return true; if (!isdigit(str.at(0))) return false; else str.erase(0,1); while (!str.empty() && isdigit(str.at(0))) str.erase(0,1); } else { return false; } if (str.empty()) return true; else return false; }