亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ngrams.cpp

?? A C++ N-grams Package 2.0 This is a simple C++ n-grams package that includes a header, the correspo
?? CPP
字號:
//====// Ngrams.cpp// - implements some methods declared in Ngrams.hpp// Notes// - this package is provided as is with no warranty// - the author is not responsible for any damage caused//   either directly or indirectly by using this package// - anybody is free to do whatever he/she wants with this//   package as long as this header section is preserved// - the author would like to thank Dr. Vlado Keselj for//   providing his Perl module code as the main reference// Created on 2004-10-28 by// - Roger Zhang (rogerz@cs.dal.ca)// Modifications// - Roger Zhang on 2004-10-31//   - a static code map is used for encoding non-printables// - Roger Zhang on 2004-11-06//   - n-grams of size 1 to n-1 are always collected, but if//     they will be included in output can be decided by the//     user through the second argument of the store methods// - Roger Zhang on 2005-09-23//   - whether n-grams of size 1 to n-1 are collected is now//     decided at contruction time, which saves computation//     time and memory when those n-grams are not interested// -// Last compiled under Linux with gcc-3//====#include "Ngrams.hpp"#include <iomanip>#include <sstream>#include <cctype>#include <list>namespace NLP{   using namespace std;   map<char, string> Ngrams::encMap; // static member   typedef map<string, int>::iterator MapIter;   //====   // internal parse methods of Ngrams   void Ngrams::parseQ()   // parse *pQue for word n-grams of size 1 to n-1   {      while (!pQue->empty()) {         int j = 0;         string ng = (*pQue)[0];         while (++j < pQue->size()) {            if (++pTotal[j] && ++pMap[j][ng] > pMax[j]) {               pMax[j] = pMap[j][ng];            }            ng += " " + (*pQue)[j];         }         if (++pTotal[j] && ++pMap[j][ng] > pMax[j]) {            pMax[j] = pMap[j][ng];         }         pQue->pop_front();      }   }   void Ngrams::parseR(string *s, bool once)   // parse string for n-grams of size 1 to n-1   {      if (once) { // single scan         for (int k = s->length() - 1; k > 0; k--) {            if (++pMap[k][s->erase(k, 1)] > pMax[k]) {               pMax[k] = pMap[k][*s];            }            pTotal[k]++;         }      } else { // multiple scan         for (string ss(*s); !ss.empty(); ss = s->erase(0, 1)) {            for (int k = ss.length(); k; ss.erase(--k, 1)) {               if (++pMap[k][ss] > pMax[k]) {                  pMax[k] = pMap[k][ss];               }               pTotal[k]++;            }         }      }   }   void Ngrams::parseL(const string &s)   // parse string for letter n-grams   {      for (int i = pStr->length(), j = s.length(), k = 0; k < j; k++) {         if (isalpha(s[k]) && ++i) {            // alphabetical letters are converted to upper case            pStr->push_back(toupper(s[k]));         } else if (i && (*pStr)[i - 1] != ' ' && i++) {            // any other characters are treated as spaces,            // and consecutive spaces are treated as one            pStr->push_back(' ');         } else { /* ignore s[k] */ }      }      parseB(s, false);   }   void Ngrams::parseB(const string &s, bool raw)   // parse string for byte n-grams   {      if (raw) {         pStr->append(s);      }      int i = 0, j = pStr->length() - size;      while (i <= j) {         string ng = pStr->substr(i++, size);         if (++pMap[size][ng] > pMax[size]) {            pMax[size] = pMap[size][ng];         }         pTotal[size]++;         if (incremental) { // collect shorter n-grams            parseR(&ng, true);         }      }      pStr->erase(0, i);      // note that during file processing, the remainder of each      // line except the last will be prepended to the next line      if (!processingFile && incremental) {         parseR(pStr, false);      }   } // Ngrams::parseB   void Ngrams::parseW(const string &s)   // parse string for word n-grams   {      int i, j, k = s.length();      for (i = j = 0; j < k; i = j) {         if (isalpha(s[i])) { // hit left boundary of a word            string word;            do {               word += tolower(s[j++]);            } while (j < k && isalpha(s[j])); // find rite boundary            pQue->push_back(word);         } else if (isdigit(s[i])) { // hit left boundary of a number            bool decimalPoint = false;            while (++j < k) { // find rite boundary               // there can be only 1 decimal point in a number               // things like 10..20 are two numbers               // 9.99. is 1 number but the 2nd point marks its end               if (s[j] == '.' && !decimalPoint) { // first point                  decimalPoint = true; // ok, record its occurrence               } else if (!isdigit(s[j])) { // any other non-digit                  break;             // marks the end of the number               }            }            pQue->push_back("<NUMBER>");         } else { // punctuation marks and/or white spaces            ++j; // just skip over         }      }      k = pQue->size() - size;      for (i = 0; i <= k; i++) { // collect n-grams         string ng = (*pQue)[0];         for (j = 1; j < size; ng += " " + (*pQue)[j++]) {            if (incremental && ++pTotal[j] && ++pMap[j][ng] > pMax[j]) {               pMax[j] = pMap[j][ng];            }         }         if (++pTotal[size] && ++pMap[size][ng] > pMax[size]) {            pMax[size] = pMap[size][ng];         }         // when loop ends, the words left in the queue are the ones         pQue->pop_front(); // significant for consecutive processing      }      if (!processingFile && incremental) { // same reason as for parseR         parseQ();      }   } // Ngrams::parseW   //====   // external helper methods for store operations   static string numToStr(double num) // atof reversed   {      ostringstream oss;      oss << setprecision(16) << num;      return oss.str();   }   void addHeader(void *buf, bool toFile, int k, int total, int max)   // only useful when storing result of incremental operations   {      if (toFile) {         ostream *o = (ostream*)buf;         (*o) << "\n" << k << "-grams  (total count = " << total              << "  top frequency = " << max << ")\n"              << "------------------------------------------------\n";      } else {         string *p = (string*)buf;         p->append("\n");         p->append(numToStr(k) + "-grams  (total count = ");         p->append(numToStr(total) + "  top frequency = ");         p->append(numToStr(max) + ")\n");         p->append("------------------------------------------------\n");      }   }   void appendS(string &s, const MapIter &i, int n, map<char, string> *m)   // append a (possibly normalized) map entry to string   {      for (int k = 0; k < i->first.length(); s += (*m)[i->first[k++]]);      s += "\t ";      if (n) {         s += numToStr(i->second / double(n)) + "\n";      } else {         s += numToStr(i->second) + "\n";      }   }   void appendF(ostream &o, const MapIter &i, int n, map<char, string> *m)   // append a (possibly normalized) map entry to ostream   {      for (int k = 0; k < i->first.length(); o << (*m)[(i->first)[k++]]);      o << "\t ";      if (n) {         o << setprecision(16) << i->second / double(n) << endl;      } else {         o << i->second << endl;      }   }   static bool lessThan(MapIter i, MapIter j) // helper function for sorting   {      return i->second > j->second;   }   //====   // internal store methods of Ngrams   void Ngrams::storeK(void *buf, int o, int f, int n, bool toFile, int k)   // store k-grams to buffer   {      if (!f || f > pMap[k].size()) { // only store the top 'f' n-grams         f = pMap[k].size();      }      if (n == NORMALIZE_BY_MAX) { // normalize against top frequency         n = pMax[k];      } else if (n == NORMALIZE_BY_SUM) { // normalize against total n-grams         n = pTotal[k];      } else { // no normalization         n = 0;      }      if (o == ORDER_BY_FREQUENCY) { // descending order by frequency         // put contents of the map in a list sorted by frequency         list<MapIter> t;         for (MapIter i = pMap[k].begin();                      i != pMap[k].end(); t.push_back(i++));         t.sort(lessThan);         // store contents of the sorted list         for (list<MapIter>::iterator j = t.begin(); f--; j++) {            if (toFile) {               appendF(*(ostream*)buf, *j, n, &encMap);            } else {               appendS(*(string*)buf, *j, n, &encMap);            }         }      } else { // just store contents of the map         for (MapIter i = pMap[k].begin(); f--; i++) {            if (toFile) {               appendF(*(ostream*)buf, i, n, &encMap);            } else {               appendS(*(string*)buf, i, n, &encMap);            }         }      }   } // Ngrams::storeK   void Ngrams::storeB(void *buf, int o, int f, int n, bool toFile)   // store to a buffer that can be either a string or an ostream   {      if (incremental) {         for (int k = 1; k < size; k++) {            addHeader(buf, toFile, k, pTotal[k], pMax[k]);            storeK(buf, o, f, n, toFile, k);         }         addHeader(buf, toFile, size, pTotal[size], pMax[size]);      }      storeK(buf, o, f, n, toFile, size);   }   //====   // public methods of Ngrams   Ngrams::Ngrams(int n, bool inc, int t)      : size(n), incremental(inc), type(t), processingFile(false)   {      pMax = new int[size + 1];      pTotal = new int[size + 1];      pStr = new string();      pQue = new deque<string>();      pMap = new map<string, int>[size + 1];      for (int i = 0; i++ < size; pTotal[i] = pMax[i] = 0) {         pMap[i].clear();      }      if (encMap.empty()) { // initialize code table (only once)         encMap['\0'] = "\\0", encMap[char(1)] = "\\1";         encMap[char(2)] = "\\2", encMap[char(3)] = "\\3";         encMap[char(4)] = "\\4", encMap[char(5)] = "\\5";         encMap[char(6)] = "\\A", encMap['\a'] = "\\a";         encMap['\b'] = "\\b", encMap['\t'] = "\\t";         encMap['\n'] = "\\n", encMap['\v'] = "\\v";         encMap['\f'] = "\\f", encMap['\r'] = "\\r";         encMap[char(14)] = "\\o", encMap[char(15)] = "\\i";         encMap[char(16)] = "\\l", encMap[char(17)] = "\\6";         encMap[char(18)] = "\\7", encMap[char(19)] = "\\8";         encMap[char(20)] = "\\9", encMap[char(21)] = "\\N";         encMap[char(22)] = "\\S", encMap[char(23)] = "\\T";         encMap[char(24)] = "\\c", encMap[char(25)] = "\\E";         encMap[char(26)] = "\\s", encMap[char(27)] = "\\e";         encMap[char(28)] = "\\F", encMap[char(29)] = "\\G";         encMap[char(30)] = "\\R", encMap[char(31)] = "\\U";         for (int i = 32; ++i < 127; encMap[char(i)] = char(i));         encMap['\\'] = "\\\\", encMap['^'] = "\\^";         encMap['_'] = "\\_", encMap[' '] = "_";         encMap['`'] = "\\`", encMap[char(127)] = "\\d";      }   } // Ngrams::Ngrams   Ngrams::~Ngrams()   {      delete pStr;      delete pQue;      delete [] pMap;      delete [] pMax;      delete [] pTotal;   }   void Ngrams::parse(istream &in) // parse file   {      processingFile = true;      pStr->clear(), pQue->clear();      for (string s; getline(in, s); parse(s)) {         if (type == BYTE_GRAM) {            s += '\n';         }      }      if (incremental) {         (type == WORD_GRAM) ? parseQ() : parseR(pStr, false);      }      processingFile = false;   }   void Ngrams::parse(const string &s) // parse string   {      if (!processingFile) {         pStr->clear(), pQue->clear();      }      if (type == WORD_GRAM) {         parseW(s);      } else if (type == BYTE_GRAM) {         parseB(s, true);      } else { // letter n-grams         if (!pStr->empty() && *(pStr->rbegin()) != ' ') {            pStr->push_back(' ');         }         parseL(s);      }   }   void Ngrams::reset() // clear previous result   {      pStr->clear(), pQue->clear();      for (int i = 0; i++ < size; pTotal[i] = pMax[i] = 0) {         pMap[i].clear();      }   }} // namespace NLP

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产最新精品免费| 欧美美女直播网站| 国产91在线观看| 国产一区不卡视频| 国产成人在线影院| 国产suv精品一区二区6| 国产盗摄一区二区三区| 成人va在线观看| 97久久精品人人做人人爽50路| 高清日韩电视剧大全免费| 成人短视频下载| 一本久久a久久精品亚洲| 91黄视频在线观看| 精品视频一区二区不卡| 欧美中文字幕不卡| 日韩一级二级三级精品视频| 成人免费一区二区三区视频| 国产精品视频在线看| 亚洲精品中文在线| 亚洲电影中文字幕在线观看| 日韩精品亚洲一区二区三区免费| 奇米精品一区二区三区在线观看 | 久久精品视频在线看| 国产女人18毛片水真多成人如厕| 国产精品嫩草影院av蜜臀| 夜夜操天天操亚洲| 免费看黄色91| 成人一区二区三区在线观看| 91视频观看视频| 欧美日韩不卡一区二区| ww亚洲ww在线观看国产| 日韩一区在线看| 日韩国产在线一| 国产成人一级电影| 在线观看av不卡| 久久综合视频网| 亚洲免费三区一区二区| 日本欧美肥老太交大片| 成人国产亚洲欧美成人综合网| 色88888久久久久久影院按摩 | 亚洲精品国产精华液| 丝袜亚洲另类丝袜在线| 国产高清不卡一区二区| 91久久精品网| 久久精品人人做人人综合 | 不卡的看片网站| 欧美日韩aaaaaa| 国产欧美日韩另类视频免费观看 | 成人国产视频在线观看| 欧美日韩国产高清一区二区三区 | 免费日本视频一区| 成人黄色大片在线观看| 日韩午夜小视频| 日韩美女视频一区| 精品中文字幕一区二区小辣椒| 91欧美激情一区二区三区成人| 91精品国产综合久久久久久久 | 国产成人一区二区精品非洲| 在线一区二区视频| 欧美激情资源网| 蜜桃视频在线一区| 欧美午夜免费电影| 综合久久久久久久| 国产在线播放一区| 欧美日韩免费高清一区色橹橹| 欧美国产一区二区| 麻豆freexxxx性91精品| 在线看国产一区二区| 日本一区二区三区电影| 久久精品国产亚洲一区二区三区| 欧美在线观看一区二区| 中文幕一区二区三区久久蜜桃| 久久国产欧美日韩精品| 欧美日韩国产小视频| 亚洲人成亚洲人成在线观看图片 | 精品国产自在久精品国产| 一区二区国产盗摄色噜噜| 成人综合婷婷国产精品久久免费| 日韩一区二区三区精品视频| 亚洲在线视频一区| 99久久精品情趣| 欧美国产日韩在线观看| 国产一区二区三区高清播放| 91精品欧美久久久久久动漫| 亚洲国产精品天堂| 欧美中文字幕久久 | 91香蕉视频污在线| 中文字幕乱码日本亚洲一区二区| 国内精品伊人久久久久av影院 | 亚洲不卡在线观看| 在线观看av一区二区| 亚洲男人的天堂在线观看| av爱爱亚洲一区| 亚洲国产精品成人久久综合一区| 久久国产夜色精品鲁鲁99| 日韩一区二区电影在线| 日本美女视频一区二区| 9191成人精品久久| 日韩不卡一二三区| 91精品欧美综合在线观看最新| 日韩av一区二区三区四区| 欧美精三区欧美精三区| 视频一区中文字幕| 欧美日韩国产一级片| 日本中文字幕一区二区视频 | 国产午夜精品美女毛片视频| 国产福利一区二区三区视频 | 国产一区二区视频在线播放| 欧美大胆一级视频| 精品一区二区免费视频| 久久你懂得1024| 国产.欧美.日韩| 国产精品久久久久久久久果冻传媒| 不卡的av在线| 亚洲精品日产精品乱码不卡| 欧美三级韩国三级日本三斤| 偷拍日韩校园综合在线| 日韩一卡二卡三卡四卡| 国产麻豆午夜三级精品| 中文字幕一区二区在线观看 | 国产精品三级视频| 99精品久久免费看蜜臀剧情介绍| 自拍视频在线观看一区二区| 欧美日韩中文字幕一区| 美日韩一级片在线观看| 久久久精品免费观看| 97久久超碰精品国产| 亚洲综合丝袜美腿| 日韩午夜激情视频| 成人动漫一区二区在线| 亚洲在线成人精品| 欧美哺乳videos| 成人福利视频在线| 性久久久久久久| 国产偷国产偷精品高清尤物 | 自拍偷自拍亚洲精品播放| 欧美在线啊v一区| 美女在线视频一区| 国产精品午夜春色av| 欧美日本韩国一区| 国产剧情在线观看一区二区| 日韩毛片在线免费观看| 日韩一区二区电影在线| 波多野结衣中文字幕一区二区三区| 一区二区三区精品视频在线| 日韩色视频在线观看| eeuss鲁片一区二区三区在线观看| 亚洲一二三四区不卡| 久久综合久久鬼色| 一本大道av伊人久久综合| 久久99精品一区二区三区 | 成人高清免费在线播放| 亚洲成av人片| 国产精品嫩草影院av蜜臀| 欧美一卡二卡在线| 欧美zozozo| 99久久精品免费观看| 蜜臀精品久久久久久蜜臀| 亚洲欧洲综合另类| 精品国产一区二区三区忘忧草| 日本高清无吗v一区| 国产大陆精品国产| 午夜精品视频在线观看| 国产精品剧情在线亚洲| 精品国产1区二区| 欧美亚洲动漫精品| 成人黄色免费短视频| 精品在线观看免费| 一区二区三区精品| 欧美激情一区不卡| 日韩免费高清av| 欧美影院精品一区| 91在线视频在线| 国产精品亚洲视频| 久久99久久99小草精品免视看| 亚洲一区二区成人在线观看| 亚洲国产精品成人综合| 精品免费视频一区二区| 欧美猛男男办公室激情| 99国产精品一区| 大尺度一区二区| 国产一区二区三区精品欧美日韩一区二区三区 | 婷婷成人激情在线网| ...中文天堂在线一区| 久久综合九色综合欧美98| 在线不卡免费av| 欧美亚洲国产一区二区三区va| 国产传媒一区在线| 国内外成人在线视频| 蜜桃一区二区三区在线| 日韩专区中文字幕一区二区| 亚洲精品国产精品乱码不99| 国产精品久久久久四虎| 国产日韩精品一区二区浪潮av| 精品久久久久久最新网址| 91精品国产综合久久精品图片| 欧美日韩一级二级三级| 欧美日韩亚洲另类| 欧美专区日韩专区| 欧美日韩一区二区三区四区五区 |