| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #include <fstream> |
| #include <vector> |
| #include <string.h> |
| using namespace std; |
|
|
| #include "modos.hpp" |
| #include "tip_var.hpp" |
| #include "fonemas.hpp" |
| #include "descriptor.hpp" |
| #include "utilidades.hpp" |
| #include "xmlfile.hpp" |
| #include "lc-star.hpp" |
| #include "ecessinterfaces.hpp" |
|
|
| Lcstar *Lcstar::lc=NULL; |
| invLcstar *invLcstar::invlc=NULL; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| EcessInterfaces::EcessInterfaces(int * n_tok, Token * f_tok){ |
|
|
| lc = Lcstar::getLcstar(); |
| invlc = invLcstar::getinvLcstar(); |
|
|
| numero_de_tokens = n_tok; |
| f_tokenizada = f_tok; |
| |
| |
| |
| output = NULL; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| void EcessInterfaces::Inicio(char * file){ |
| if (file == NULL) { |
| output = new XmlFile(); |
| } |
| else{ |
| output = new XmlFile(file); |
| } |
| } |
|
|
|
|
| |
| |
| |
| |
| |
| |
| EcessInterfaces::~EcessInterfaces() |
| { |
| delete lc; |
| delete invlc; |
| if (output) { |
| delete output; |
| } |
| } |
|
|
|
|
| |
| |
| |
| |
| void EcessInterfaces::escribe_salida_frase(char mod, vector<Vector_descriptor_objetivo> &objetivo, int n){ |
|
|
| output->openElement("s"); |
| vector<string> atts; |
| |
| vector<Vector_descriptor_objetivo>::iterator in = objetivo.begin(); |
|
|
|
|
| for (int j = 0; j < *numero_de_tokens; j++){ |
| atts.clear(); |
| atts.push_back("token"); |
| if ( *f_tokenizada[j].token == '"') { |
| atts.push_back("""); |
| } |
| else if (*f_tokenizada[j].token == '&'){ |
| atts.push_back("&"); |
| } |
| else { |
| atts.push_back(f_tokenizada[j].token); |
| } |
| output->openElement("TOKEN", atts, 1); |
| for (int i = 0; i < f_tokenizada[j].n_palabras; i++) { |
| atts.clear(); |
| atts.push_back("word"); |
| if (*f_tokenizada[j].token == '"') { |
| atts.push_back("""); |
| } |
| else if (*f_tokenizada[j].token == '&'){ |
| atts.push_back("&"); |
| } |
| else { |
| atts.push_back(f_tokenizada[j].palabras[i].pal); |
| } |
| |
| output->openElement("WORD", atts, 2); |
| atts.clear(); |
| output->openElement("POS", 3); |
| if (f_tokenizada[j].palabras[i].cat_gramatical[0] == VERBO) { |
| get_verb_atts(atts, f_tokenizada[j].palabras[i].cat_verbal[0]); |
| output->closeElement("VER", atts, 4); |
| |
| } |
| else { |
| if (f_tokenizada[j].palabras[i].xenero) { |
| atts.push_back("gender"); |
| atts.push_back(lc->genero[f_tokenizada[j].palabras[i].xenero]); |
| } |
| if (f_tokenizada[j].palabras[i].numero) { |
| atts.push_back("number"); |
| atts.push_back(lc->numero[f_tokenizada[j].palabras[i].numero]); |
| } |
| output->closeElement(lc->categoria[f_tokenizada[j].palabras[i].cat_gramatical[0]].c_str(), atts, 4); |
| |
| } |
| output->closeElement("POS", 3); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| output->closeElement("PHONETIC", 3, escribe_transcripcion(f_tokenizada[j].palabras[i].tr_fon)); |
| if (mod == 2) { |
| escribe_phon(&in, n, f_tokenizada[j].palabras[i].pal); |
| } |
| output->closeElement("WORD", 2); |
| } |
| output->closeElement("TOKEN", 1); |
| } |
| output->closeElement("s"); |
| } |
|
|
| void EcessInterfaces::escribe_phon( vector<Vector_descriptor_objetivo>::iterator* in, int &n, char * pal) { |
| vector<string> a; |
| char duracion[6]; |
| char d[6]; |
| char f[3]; |
| float fi,fm,ff; |
| int dur; |
| |
| while (n && !strcmp((*in)->palabra, pal)){ |
| |
| a.clear(); |
| a.push_back("phoneme"); |
| a.push_back((*in)->semifonema); |
| a.push_back("duration"); |
| dur = (int) (((*in)->duracion_1 + (*in)->duracion_2) * 1000.0); |
| sprintf(duracion, "%d", dur); |
| a.push_back(duracion); |
| output->openElement("PHON", a, 3); |
| output->openElement("frequency", 4); |
| a.clear(); |
| a.push_back("time"); |
| a.push_back("0"); |
| a.push_back("value"); |
| (*in)->devuelve_frecuencias(&fi, &fm, &ff); |
| sprintf(f, "%d", (int) fi); |
| a.push_back(f); |
| output->closeElement("pair", a, 5); |
| a.clear(); |
| a.push_back("time"); |
| sprintf(d, "%d", (int) ((*in)->duracion_1 * 1000.0)); |
| a.push_back(d); |
| a.push_back("value"); |
| sprintf(f, "%d", (int) fm); |
| a.push_back(f); |
| output->closeElement("pair", a, 5); |
| a.clear(); |
| a.push_back("time"); |
| a.push_back(duracion); |
| a.push_back("value"); |
| sprintf(f, "%d", (int) ff); |
| a.push_back(f); |
| output->closeElement("pair", a, 5); |
| output->closeElement("frequency", 4); |
| output->openElement("energy", 4); |
| a.clear(); |
| a.push_back("time"); |
| a.push_back("0"); |
| a.push_back("value"); |
| sprintf(f, "%d", (int) (*in)->potencia); |
| a.push_back(f); |
| output->closeElement("pair", a, 5); |
| output->closeElement("energy", 4); |
| if ((*in)->info_silaba) { |
| a.clear(); |
| a.push_back("last-syllable"); |
| if ((*in)->info_silaba == 2) { |
| a.push_back("true"); |
| } |
| else { |
| a.push_back("false"); |
| } |
| if ((*in)->acento) { |
| a.push_back("accent"); |
| a.push_back("primary"); |
| } |
| output->openElement("syllable", a, 4); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| output->closeElement("syllable", 4); |
| } |
| output->closeElement("PHON", 3); |
| n--; |
| (*in)++; |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| char *EcessInterfaces::escribe_transcripcion(char *tr){ |
| char *str = tr; |
| char *pp; |
| pp = strchr(str, '^'); |
| while (pp!=NULL) { |
| *pp = *(pp - 1); |
| *(pp - 1) = STRESS_MARK; |
| str = pp; |
| pp = strchr(str, '^'); |
| } |
| return tr; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| char *EcessInterfaces::lee_transcripcion(char *tr){ |
| char *str = tr; |
| char *pp; |
| pp = strchr(str, STRESS_MARK); |
| while (pp != NULL) { |
| *pp = *(pp + 1); |
| *(pp + 1) = '^'; |
| str = pp ; |
| pp = strchr(str, STRESS_MARK); |
| } |
| return tr; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void EcessInterfaces::get_verb_atts(vector<string> &atts, unsigned char codigo){ |
| switch (codigo) { |
| case 180: |
| case 181: |
| case 182: |
| atts.push_back("mood"); |
| atts.push_back("gerund"); |
| break; |
| case 183: |
| atts.push_back("mood"); |
| atts.push_back("participle"); |
| atts.push_back("number"); |
| atts.push_back("singular"); |
| atts.push_back("gender"); |
| atts.push_back("masculine"); |
| break; |
| case 184: |
| atts.push_back("mood"); |
| atts.push_back("participle"); |
| atts.push_back("number"); |
| atts.push_back("singular"); |
| atts.push_back("gender"); |
| atts.push_back("feminine"); |
| break; |
| case 185: |
| atts.push_back("mood"); |
| atts.push_back("participle"); |
| atts.push_back("number"); |
| atts.push_back("plural"); |
| atts.push_back("gender"); |
| atts.push_back("masculine"); |
| break; |
| case 186: |
| atts.push_back("mood"); |
| atts.push_back("participle"); |
| atts.push_back("number"); |
| atts.push_back("plural"); |
| atts.push_back("gender"); |
| atts.push_back("feminine"); |
| break; |
| case 187: |
| atts.push_back("mood"); |
| atts.push_back("participle"); |
| atts.push_back("number"); |
| atts.push_back("singular"); |
| atts.push_back("gender"); |
| atts.push_back("masculine"); |
| break; |
| case 188: |
| atts.push_back("mood"); |
| atts.push_back("participle"); |
| atts.push_back("number"); |
| atts.push_back("singular"); |
| atts.push_back("gender"); |
| atts.push_back("feminine"); |
| break; |
| case 189: |
| atts.push_back("mood"); |
| atts.push_back("participle"); |
| atts.push_back("number"); |
| atts.push_back("plural"); |
| atts.push_back("gender"); |
| atts.push_back("masculine"); |
| break; |
| case 190: |
| atts.push_back("mood"); |
| atts.push_back("participle"); |
| atts.push_back("number"); |
| atts.push_back("plural"); |
| atts.push_back("gender"); |
| atts.push_back("feminine"); |
| break; |
| case 191: |
| atts.push_back("mood"); |
| atts.push_back("participle"); |
| atts.push_back("number"); |
| atts.push_back("singular"); |
| atts.push_back("gender"); |
| atts.push_back("masculine"); |
| break; |
| case 192: |
| atts.push_back("mood"); |
| atts.push_back("participle"); |
| atts.push_back("number"); |
| atts.push_back("singular"); |
| atts.push_back("gender"); |
| atts.push_back("feminine"); |
| break; |
| case 193: |
| atts.push_back("mood"); |
| atts.push_back("participle"); |
| atts.push_back("number"); |
| atts.push_back("plural"); |
| atts.push_back("gender"); |
| atts.push_back("masculine"); |
| break; |
| case 194: |
| atts.push_back("mood"); |
| atts.push_back("participle"); |
| atts.push_back("number"); |
| atts.push_back("plural"); |
| atts.push_back("gender"); |
| atts.push_back("feminine"); |
| break; |
| default : |
| unsigned char tense = (unsigned char) ((codigo - 1) / 18); |
| unsigned char person = (unsigned char) ((codigo - 1) % 6); |
| switch (person) { |
| case 0: |
| atts.push_back("number"); |
| atts.push_back("singular"); |
| atts.push_back("person"); |
| atts.push_back("1"); |
| break; |
| case 1: |
| atts.push_back("number"); |
| atts.push_back("singular"); |
| atts.push_back("person"); |
| atts.push_back("2"); |
| break; |
| case 2: |
| atts.push_back("number"); |
| atts.push_back("singular"); |
| atts.push_back("person"); |
| atts.push_back("3"); |
| break; |
| case 3: |
| atts.push_back("number"); |
| atts.push_back("plural"); |
| atts.push_back("person"); |
| atts.push_back("1"); |
| break; |
| case 4: |
| atts.push_back("number"); |
| atts.push_back("plural"); |
| atts.push_back("person"); |
| atts.push_back("2"); |
| break; |
| case 5: |
| atts.push_back("number"); |
| atts.push_back("plural"); |
| atts.push_back("person"); |
| atts.push_back("3"); |
| break; |
| } |
| switch (tense) { |
| case 0: |
| atts.push_back("mood"); |
| atts.push_back("indicative"); |
| atts.push_back("tense"); |
| atts.push_back("present"); |
| break; |
| case 1: |
| atts.push_back("mood"); |
| atts.push_back("indicative"); |
| atts.push_back("tense"); |
| atts.push_back("imperfect"); |
| break; |
| case 2: |
| atts.push_back("mood"); |
| atts.push_back("indicative"); |
| atts.push_back("tense"); |
| atts.push_back("past"); |
| break; |
| case 3: |
| atts.push_back("mood"); |
| atts.push_back("indicative"); |
| atts.push_back("tense"); |
| atts.push_back("pluperfect"); |
| break; |
| case 4: |
| atts.push_back("mood"); |
| atts.push_back("indicative"); |
| atts.push_back("tense"); |
| atts.push_back("future"); |
| break; |
| case 5: |
| atts.push_back("mood"); |
| atts.push_back("conditional"); |
| break; |
| case 6: |
| atts.push_back("mood"); |
| atts.push_back("subjunctive"); |
| atts.push_back("tense"); |
| atts.push_back("present"); |
| break; |
| case 7: |
| atts.push_back("mood"); |
| atts.push_back("subjunctive"); |
| atts.push_back("tense"); |
| atts.push_back("imperfect"); |
| break; |
| case 8: |
| atts.push_back("mood"); |
| atts.push_back("subjunctive"); |
| atts.push_back("tense"); |
| atts.push_back("future"); |
| break; |
| case 9: |
| atts.push_back("mood"); |
| atts.push_back("imperative"); |
| break; |
| case 11: |
| atts.push_back("mood"); |
| atts.push_back("infinitive"); |
| break; |
| } |
| } |
| } |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void EcessInterfaces::lcstar2cotovia(const char *pos, const char **atts, t_frase_separada * fs){ |
| |
| for (int i = 0; atts[i]; i += 2) { |
| #ifdef _TRAZA |
| fprintf(stderr," %s='%s'", atts[i], atts[i + 1]); |
| #endif |
| if (!strcasecmp(atts[i], "gender")) { |
| fs->xenero = invlc->genero[*(atts[i + 1])]; |
| } |
| else if (!strcasecmp(atts[i], "number")) { |
| fs->numero = invlc->numero[*(atts[i + 1])]; |
| } |
|
|
| } |
| fs->cat_gramatical[0] = invlc->categoria[string(pos)]; |
| |
| } |
|
|
|
|