From 617155fe562652c859a380d85cc5710783d79448 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 1 Feb 2016 09:30:04 -0500 Subject: Added emoji freevar Strings of emojis are tokenized separately from anything else, and added to an emoticon freevar, which is mixed in with regular emoticons like :P. This breaks old-style freevars like $name$ and $noun$ so some legacy support for compatibility is left in but eventually $name$ should be made into an actual new freevar. Emoji data is from gemoji (https://github.com/github/gemoji). --- freevars.cpp | 58 ++++++++++++++++++++++------------------------------------ 1 file changed, 22 insertions(+), 36 deletions(-) (limited to 'freevars.cpp') diff --git a/freevars.cpp b/freevars.cpp index 54c5aab..4429d00 100644 --- a/freevars.cpp +++ b/freevars.cpp @@ -1,46 +1,32 @@ #include "freevars.h" #include -#include +#include "kgramstats.h" -freevars::freevars() +freevar::freevar(word& w, std::string file) : w(w) { - vars = new std::map* >(); + std::ifstream infile(file); + if (infile) + { + std::string line; + while (getline(infile, line)) + { + instances.insert(line); + w.forms.add(line); + } + } } -void freevars::addVar(std::string name, std::string filename) +bool freevar::check(std::string f) const { - std::vector* eltlist = new std::vector(); - - std::ifstream infile(filename.c_str()); - if (infile) - { - std::string line; - - while (getline(infile, line)) - { - eltlist->push_back(line); - } - } else { - eltlist->push_back(""); - } - - (*vars)[name] = eltlist; + return (instances.count(f) == 1); } -std::string freevars::parse(std::string in) +void freevar::add(std::string f) { - std::string res(in); - - for (std::map* >::iterator it = vars->begin(); it != vars->end(); it++) - { - std::string tofind = "$" + it->first + "$"; - size_t fpos; - while ((fpos = res.find(tofind)) != std::string::npos) - { - int r = rand() % it->second->size(); - res.replace(fpos, tofind.length(), (*it->second)[r], 0, std::string::npos); - } - } - - return res; -} \ No newline at end of file + instances.insert(f); +} + +word& freevar::getWord() +{ + return w; +} -- cgit 1.4.1