commit 03c58d75e346b1607885e0d6e6d2f9ed2bb75e67 Author: Tanmai Khanna Date: Mon Jun 17 17:54:27 2019 +0530 Working code to Parse LU diff --git a/src/anaphora.cc b/src/anaphora.cc index be24c27..96439c1 100644 --- a/src/anaphora.cc +++ b/src/anaphora.cc @@ -1,5 +1,6 @@ #include #include +#include int main() { @@ -7,9 +8,34 @@ int main() input_char = fgetc(stdin); + char input_stream[100] = ""; + char output_stream[100] = ""; + + int flag_LU = 0; + while(input_char!=EOF) { - printf("%c",input_char); + fprintf(stdout, "%c",input_char); + + if(input_char == '^') + flag_LU = 1; + + if(flag_LU == 1) //Part of an LU + strcat(input_stream, string(input_char)) + + if(flag_LU == 0) //Not Part of an LU + fprintf(stdout, "%c", input_char); + + if(input_char == '$') + { + flag_LU = 0; + + LU = parse(input_stream); + + } + + + input_char = fgetc(stdin); } diff --git a/src/parse_biltrans.cc b/src/parse_biltrans.cc new file mode 100644 index 0000000..10d0e40 --- /dev/null +++ b/src/parse_biltrans.cc @@ -0,0 +1,148 @@ +#include +#include + +using namespace std; + +class LexicalUnit +{ + +private: + + vector sl_form; + vector tl_form; + + vector< vector > sl_tags; + vector< vector > tl_tags; + +public: + + LexicalUnit(vector input_LU) + { + int seenSlash = 0; + int seenTag = 0; + + vector temptag; + + for (auto i = input_LU.begin(); i != input_LU.end(); ++i) + { + if(*i == '/') + seenSlash++; + + else if(seenSlash == 0) //sl + { + sl_form.push_back(*i); //add to the sl form + + if(*i == '<') //start reading tag + seenTag++; + + else if(seenTag == 1) //inside a tag + { + if(*i == '>') //if tag ends + { + seenTag--; + sl_tags.push_back(temptag); //add tag to list of sl tags + + temptag.clear(); + } + else + { + temptag.push_back(*i); //add char to current tag + } + } + } + + else //tl + { + tl_form.push_back(*i); //add to the tl form + + if(*i == '<') //start reading tag + seenTag++; + + else if(seenTag == 1) //inside a tag + { + if(*i == '>') //if tag ends + { + seenTag--; + tl_tags.push_back(temptag); //add tag to list of tl tags + + temptag.clear(); + } + else + { + temptag.push_back(*i); //add char to current tag + } + } + } + } + } + + vector get_sl_form() + { + return sl_form; + } + + vector get_tl_form() + { + return tl_form; + } + + vector< vector > get_sl_tags() + { + return sl_tags; + } + + vector< vector > get_tl_tags() + { + return tl_tags; + } + +}; + +void print(vector const &input) +{ + for (int i = 0; i < input.size(); i++) { + std::cout << input.at(i); + } +} + +void print_tags(vector< vector > const &input) +{ + for (int i = 0; i < input.size(); i++) { + for(int j = 0; j < input.at(i).size(); j++) { + cout << input.at(i).at(j); + } + cout << " "; + } +} + +int main() +{ + vector inputlu; + char input_char; + + input_char = fgetc(stdin); + + while(input_char != '\n') + { + inputlu.push_back(input_char); + + input_char = fgetc(stdin); + } + + LexicalUnit lu(inputlu); + + cout << "SL: "; + print(lu.get_sl_form()); + cout << endl << "SL tags: "; + print_tags(lu.get_sl_tags()); + cout << endl << "TL: "; + print(lu.get_tl_form()); + cout << endl << "TL tags: "; + print_tags(lu.get_tl_tags()); + cout << endl; + + return 0; +} + + +