From c8e834c362ea80a781fa870338182a4c81ad3d78 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 15 Feb 2016 09:32:02 -0500 Subject: Fixed issue when names.txt was not present Also removed any code mentioning $noun$ because it turns out the current version of the canonical corpus doesn't even use it anymore. --- kgramstats.cpp | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'kgramstats.cpp') diff --git a/kgramstats.cpp b/kgramstats.cpp index f91ef52..f3fbcb2 100644 --- a/kgramstats.cpp +++ b/kgramstats.cpp @@ -162,7 +162,7 @@ kgramstats::kgramstats(std::string corpus, int maxK) { if ( // Legacy freevars should be distinct from tokens containing similar words - (canonical.find("$name$") != std::string::npos) || (canonical.find("$noun$") != std::string::npos) + (canonical.find("$name$") != std::string::npos) // Words with no letters will be mangled by the spell checker || (canonical.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") == std::string::npos) ) @@ -588,31 +588,20 @@ std::string kgramstats::randomSentence(int n) // Replace old-style freevars while I can't be bothered to remake the corpus yet std::vector fv_names; std::ifstream namefile("names.txt"); - while (!namefile.eof()) + if (namefile.is_open()) { - std::string l; - getline(namefile, l); - fv_names.push_back(l); - } - - int cpos; - while ((cpos = result.find("$name$")) != std::string::npos) - { - result.replace(cpos, 6, fv_names[rand() % fv_names.size()]); - } - - std::vector fv_nouns; - std::ifstream nounfile("nouns.txt"); - while (!nounfile.eof()) - { - std::string l; - getline(nounfile, l); - fv_nouns.push_back(l); - } + while (!namefile.eof()) + { + std::string l; + getline(namefile, l); + fv_names.push_back(l); + } - while ((cpos = result.find("$noun$")) != std::string::npos) - { - result.replace(cpos, 6, fv_nouns[rand() % fv_nouns.size()]); + int cpos; + while ((cpos = result.find("$name$")) != std::string::npos) + { + result.replace(cpos, 6, fv_names[rand() % fv_names.size()]); + } } return result; -- cgit 1.4.1