#include #include /* Pala BisqBottia. */ #include "dcparsfun.cc" /* Esimerkkejä on tiedoston lopussa. */ static int Huuto = 0; static int Kysymys = 0; static int Itsme = 0; static int Persoona = 0; static string Adverb = ""; static string ObjVerb = ""; static string Kasky = ""; static string Attribute = ""; static string AdjAttr = ""; static string NegComp = ""; static string Object = ""; static string Indicator = ""; static int Aikamuoto = -1; class parser { class item { morfo mfo; string word; string meaning, form, normal; public: item(const string &w, const string &rest) : word(w) { unsigned a = rest.find(','); if(a==rest.npos)return; meaning = rest.substr(0, a); while(rest[++a]==' '); unsigned b = rest.find(',', a); if(b==rest.npos)return; form = rest.substr(a, b-a); while(rest[++b]==' '); normal = htmldefix(rest.substr(b)); cerr << "Item: " << w << " = " << form << " (" << meaning << ")\n"; if(w == "!")++Huuto; if(w == "?")++Kysymys; if(form == "Verb") { if(meaning == "NegComp") NegComp = word; else if(strcasecmp(word.c_str(), "jaa")) { if(meaning == "Object" || meaning == "Subject") ObjVerb = word; mfo.init(word, "verbi"); if(mfo["tapaluokka"] == "imperatiivi") Kasky = word; if(mfo["perusmuoto"] != "ei") { if(mfo["pääluokka"] == "aktiivi") { unsigned Pers; if(mfo["persoona"] == "yksikön ensimmäinen")Pers = 1; else if(mfo["persoona"] == "yksikön toinen")Pers = 2; else if(mfo["persoona"] == "yksikön kolmas")Pers = 3; else if(mfo["persoona"] == "monikon ensimmäinen")Pers = 4; else if(mfo["persoona"] == "monikon toinen")Pers = 5; else if(mfo["persoona"] == "monikon kolmas")Pers = 6; else Pers=0; if(mfo["tapaluokka"] == "i infinitiivi" && meaning == "Object") { Indicator = mfo["perusmuoto"]; } else if(mfo["tapaluokka"] == "indikatiivi") { Indicator = mfo["perusmuoto"]; Persoona = Pers; } else if(mfo["tapaluokka"] == "konditionaali") { if(Pers==3)Persoona = 7; Indicator = word; } if(mfo["aikamuoto"] == "preesens" && Pers) Aikamuoto = 0; } } } } if(form == "Adverb" && w != "sitten" && w != "siis") if(w.size() > Adverb.size()) Adverb = w; if(form == "Code" && meaning == "Head") { if(!strcasecmp(word.c_str(), "BisqBot")) ++Itsme; } if(form == "Noun" && meaning == "Object") Object = w; if(form == "Adjective") { if(meaning == "Complement")Attribute = w; if(meaning == "AdjAttr")AdjAttr = w; } } }; vector items; public: void operator() (const string &s) { unsigned a = s.find("', a); b = s.find('<', a); register unsigned tmp = s[a+1] == '('; string word = s.substr(a+1+tmp, b-a-1-tmp*2); a = s.find('>', b); while(s[++a]==' '); string rest = s.substr(a); items.push_back(item(htmldefix(word), rest)); } } parse; static bool IsoEka = false; static string Prefix; string prehviks; static string tyylita(const string &s) { string tmp = lowercase(s); if(IsoEka)tmp[0] = toupper(tmp[0]); return prehviks + ' ' + Prefix + tmp + '\n'; } static bool OnkoPotentiaalia(const string &s) { if(!s.size() || !isfinalpha(s[0]))return false; if(s.find("??") != s.npos)return false; unsigned a=0; for(;;) { unsigned b = s.find(' ', a); string c = s.substr(a, (b == s.npos) ? s.npos : b-a); if(c == ":(" || c == ":)" || c.substr(1) == "öh" || c.substr(1) == "eh" || !strcasecmp(c.substr(0,8).c_str(), "bisqbot,") || !strcasecmp(c.c_str(), "jaha") || !strcasecmp(c.substr(0,3).c_str(), "hmm")) return false; if(b == s.npos)break; a = b+1; } return true; } int main(int argc, const char *const *argv) { string s; cerr << "Lause: " << flush; getline(cin, s); cerr << endl; if(argv[1]) { prehviks = argv[1]; if(argv[1][0]=='=')Prefix = " "; } if(!OnkoPotentiaalia(s)) { cerr << "Ei potentiaalia...\n"; return 0; } if(isupper(s[0]))IsoEka = true; cerr << "Parsing...\n"; s = query("http://www.kielikone.fi/kielikone/demot/dcparser2.shtml?Source=", s); unsigned a, b; a = s.find("
");
    if(a == s.npos)return -1;
    
    s = s.substr(a+5);
    
    a = s.find("
"); if(a != s.npos)s.replace(a, s.npos, 1, '\n'); for(b=0;;) { a = s.find('\n', b); if(a == s.npos)break; string q = s.substr(b, a-b); parse(q); b = a+1; } cerr << "Huuto="< Kasky.size() ? Adverb : Kasky; if(!Kasky.size() && Attribute.size())w += ' ' + Attribute; w += Kasky.size() ? '!' : '.'; cout << tyylita(w); } else if(Kasky.size()) { if(!Adverb.size()) { // cout << tyylita("Niin, " + Kasky + "."); // Tämä on lähinnä ärsyttävä. } else cout << tyylita((Adverb.size() > Kasky.size() ? Adverb : Kasky) + '.'); } else if(Adverb.size() && Attribute.size()) { morfo tmp(Attribute, "adjektiivi"); if(tmp["sijamuoto"] == "partitiivi") { string s = Adverb; if(!strcasecmp(s.c_str(), "kyllä"))s += ','; cout << tyylita(s + ' ' + Attribute + '.'); } } else if(AdjAttr.size() && NegComp.size()) { #if 0 if(lowercase(NegComp) == "ole") cout << tyylita("ei todellakaan."); #endif /* Köyhyys on aina väärä selitys varastamiselle - ellei siihen ole sitten joku painava syy, kuten toimeentulon uhka Ei todellakaan. ja taas hutiin Bisqbotin "ei todellakaan" on osunut tähän asti joka kerta hutiin, poistan */ } /* else if(Kysymys && Object.size()) cout << tyylita(Object + "..."); */ #if 0 else if(Indicator.size() || ObjVerb.size()) { if(Kysymys && Persoona == 2 && Itsme) cout << tyylita("en."); else if(!Kysymys) { string comm; char loppu = '.'; if(Persoona == 2 && Itsme) { if(!strncasecmp("kyllä", Adverb.c_str(), 5)) { if(Huuto) cout << tyylita("enpäs!"); else cout << tyylita("enpäs."); } else { comm = "enpäs"; if(Huuto)loppu = '!'; } } else if(Persoona == 1) { if(ObjVerb.size()) comm == "etkä"; else { if(!strncasecmp("kyllä", Adverb.c_str(), 5) || !strncasecmp("aivan", Adverb.c_str(), 5)) cout << tyylita("etpäs."); else comm = "etpäs"; } } else if(Persoona == 7) { /* Jos tähän ottaisi ObjVerb -käsittelyn, tuloksena olisi * jotain tyyliin: Eikä lähteä (lauseelle "voisi lähteä") */ cout << tyylita("eikä " + Indicator); } if(comm.size()) { string word = Indicator; if(Persoona == 1 && ObjVerb.size()) word = ObjVerb; string s; if(Aikamuoto < 0) { s = query( "http://www.kielikone.fi/kielikone/demot/formo-verbi-nominaali2.shtml?" "SCat=Verb&SFin=NonF&SVoice=Act&SModal=II-Part&" "SPerson=None&SCase=Nom&SComparison=None&" "SNumber=Sg&SClit1=None&SClit2=None&Slex=", word); } else { s = query( "http://www.kielikone.fi/kielikone/demot/formo-verbi-finiitti2.shtml?" "SCat=Verb&SFin=Fin&SVoice=Act&SModal=Imper&STense=Pr&SPerson=Sg2P&" "SClit1=None&SClit2=None&Slex=", word); } //cerr << "s='" << s << "'\n" << flush; unsigned a = s.find("
"); if(a != s.npos) { unsigned b = s.find('\n', a+=11); cout << tyylita(comm + ' ' + lowercase(htmldefix(s.substr(a, b-a))) + loppu); } } } } #endif return 0; } /* Esim: proteus:~/src$ echo 'Minusta se on pahaa mutta mä silti juon sitä töissä päivittäin'|dcparser Lause: Parsing... Item: Minusta = Pronoun (Adverbial) Item: se = Pronoun (Subject) Item: pahaa = Adjective (Complement) Item: on = Verb (Head) 'perusmuoto: olla' 'sanaluokka: verbi' 'Pääluokka: aktiivi' 'tapaluokka: indikatiivi' 'aikamuoto: preesens' 'persoona: yksikön kolmas' Item: mutta = Conjunction (ConjAttr) Item: mä = Code (Head) Item: silti = Adverb (Adverbial) Item: sitä = Pronoun (Object) Item: töissä = Noun (Adverbial) Item: päivittäin = Adverb (Adverbial) Item: juon = Verb (Head) 'perusmuoto: juoda' 'sanaluokka: verbi' 'Pääluokka: aktiivi' 'tapaluokka: indikatiivi' 'aikamuoto: preesens' 'persoona: yksikön ensimmäinen' Huuto=0,Kasky='',Adverb='päivittäin' 'perusmuoto: paha' 'sanaluokka: adjektiivi' 'luku: yksikkö' 'sijamuoto: partitiivi' Päivittäin pahaa. proteus:~/src$ echo 'Se ei ole hyvä asia.'|dcparser Lause: Parsing... Item: Se = Pronoun (Subject) Item: hyvä = Adjective (AdjAttr) Item: asia = Noun (Complement) Item: ole = Verb (NegComp) Item: . = Delimiter (Separator) Item: ei = Verb (Head) 'perusmuoto: ei' 'sanaluokka: verbi' 'Pääluokka: aktiivi' 'tapaluokka: indikatiivi' 'aikamuoto: preesens' 'persoona: yksikön kolmas' Huuto=0,Kasky='',Adverb='' 19:08|#pkmn/Warp> ja mä vähän luulen että tuollainen zoomaus on aika hidasta. tai noh, kyllä se P-III:lla menee sutjakkaasti varmaan 19:08|#pkmn/BisqBot> sutjakkaasti hidasta. */