标签:检索 测试 stream virt clu flag day main tac
研究长字符串快速全文检索技术,实现某电力公司新闻中心新闻稿件全文检索统计系统。 1、 设计实现适合新闻稿件的基础类库 2、 新闻稿件全文检索功能实现 3、 新闻稿件按照关键字统计查询
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 class Paper { 5 protected: 6 int yy, mm, dd; 7 string unite; 8 string title; 9 //there declarations for kinds of news 10 public: 11 Paper(); 12 Paper(const Paper &asp); 13 virtual ~Paper() {} 14 void SetYMDear(const int year, const int month, const int day); 15 int GetYear()const; 16 int GetMonth()const; 17 int GetDay()const; 18 string GetTitle()const; 19 string GetUnite()const; 20 void SetUnite(const string Unite); 21 void SetTitle(const string Title); 22 virtual int CountWords(const string text) = 0; 23 }; 24 Paper::Paper() :yy(0), mm(0), dd(0), unite("xxx"), title("!!!") {} 25 Paper::Paper(const Paper &asp) { yy = asp.yy; mm = asp.mm; dd = asp.dd; unite = asp.unite; title = asp.title; } 26 void Paper::SetYMDear(const int year, const int month, const int day) { yy = year, mm = month, dd = day; } 27 void Paper::SetTitle(const string Title) { title = Title; } 28 void Paper::SetUnite(const string Unite) { unite = Unite; } 29 int Paper::GetDay()const { return dd; } 30 int Paper::GetYear()const { return yy; } 31 int Paper::GetMonth()const { return mm; } 32 string Paper::GetTitle()const { return title; } 33 string Paper::GetUnite()const { return unite; } 34 class Word :virtual public Paper { 35 protected: 36 string contain; 37 public: 38 friend istream& operator >> (istream&, Word&); 39 friend ostream& operator <<(ostream&, const Word &); 40 Word(); 41 Word(const string con); 42 ~Word() { 43 44 } 45 int CountWords(const string text); 46 }; 47 istream& operator >> (istream&in, Word&rhp) { 48 in >> rhp.yy >> rhp.mm >> rhp.dd >> rhp.title >> rhp.unite >> rhp.contain; 49 return in; 50 } 51 ostream& operator <<(ostream&out, const Word &rhp) { 52 out << rhp.yy << endl 53 << rhp.mm << endl 54 << rhp.dd << endl 55 << rhp.title << endl 56 << rhp.unite << endl 57 << rhp.contain << endl; 58 return out; 59 } 60 Word::Word() :contain("xxx") { 61 62 } 63 Word::Word(const string con) { contain = con; } 64 int Word::CountWords(const string text) { 65 int ans = 0; 66 auto pos = contain.find(text); 67 while (pos != string::npos) { 68 ans++; 69 pos = contain.find(text, ++pos); 70 } 71 return ans; 72 } 73 class vedio :virtual public Paper { 74 protected: 75 string act; 76 string Vname; 77 public: 78 friend istream& operator >> (istream&, vedio&); 79 friend ostream& operator <<(ostream&, const vedio&); 80 vedio(); 81 ~vedio() {} 82 vedio(const string ac, const string vn); 83 string GetAct()const; 84 string GetVName()const; 85 int CountWords(const string text); 86 }; 87 istream& operator >> (istream&in, vedio&rhp) { 88 in >> rhp.yy >> rhp.mm >> rhp.dd >> rhp.title >> rhp.unite >> rhp.act >> rhp.Vname; 89 return in; 90 } 91 ostream& operator <<(ostream&out, const vedio &rhp) { 92 out << rhp.yy << endl 93 << rhp.mm << endl 94 << rhp.dd << endl 95 << rhp.title << endl 96 << rhp.unite << endl 97 << rhp.act << endl 98 << rhp.Vname << endl; 99 return out; 100 } 101 vedio::vedio() :act("xxx"), Vname("XXXX") {} 102 vedio::vedio(const string ac, const string vn) { act = ac, Vname = vn; } 103 string vedio::GetAct()const { return act; } 104 string vedio::GetVName()const { return Vname; } 105 int vedio::CountWords(const string text) { 106 int ans = 0; 107 int pos = act.find(text); 108 while (pos != string::npos) { 109 ans++; 110 pos = act.find(text, ++pos); 111 } 112 return ans; 113 } 114 class Record :virtual public vedio { 115 protected: 116 string ReName; 117 public: 118 friend istream& operator >> (istream&, Record&); 119 friend ostream& operator <<(ostream&, const Record &); 120 Record(); 121 ~Record() {} 122 Record(const string re); 123 int CountWords(const string text); 124 }; 125 istream& operator >> (istream&in, Record&rhp) { 126 in >> rhp.yy >> rhp.mm >> rhp.dd >> rhp.title >> rhp.unite >> rhp.act >> rhp.ReName; 127 return in; 128 } 129 ostream& operator <<(ostream&out, const Record &rhp) { 130 out << rhp.yy << endl 131 << rhp.mm << endl 132 << rhp.dd << endl 133 << rhp.title << endl 134 << rhp.unite << endl 135 << rhp.act << endl 136 << rhp.ReName << endl; 137 return out; 138 } 139 Record::Record() :ReName("XXXX") {} 140 Record::Record(const string re) { ReName = re; } 141 int Record::CountWords(const string text) { 142 return vedio::CountWords(text); 143 } 144 class Poem :virtual public Word { 145 public: 146 Poem() {} 147 ~Poem() {} 148 int CountWords(const string text); 149 }; 150 int Poem::CountWords(const string text) { 151 int ans = 0; 152 string flag = GetTitle(); 153 auto pos = flag.find(text); 154 while (pos != string::npos) { 155 ans++; 156 pos = flag.find(text, ++pos); 157 } 158 return ans; 159 } 160 class Other :virtual public Word { 161 public: 162 Other() {} 163 ~Other() {} 164 int CountWords(const string text); 165 }; 166 int Other::CountWords(const string text) 167 { 168 int ans = 0; 169 string flag = GetTitle(); 170 auto pos = flag.find(text); 171 while (pos != string::npos) { 172 ans++; 173 pos = flag.find(text, ++pos); 174 } 175 return ans; 176 } 177 178 int main() { 179 cout << "Please input kinds of News in follow fomat." << endl 180 << "Word or Poem or Other News:" << endl 181 << "Year Month Day Title Unite Contain" << endl 182 << "vedio or Record News:" << endl 183 << "Year Month Day Title Unite Abstract Filename" << endl; 184 Word a1; 185 vedio a2; 186 Record a3; 187 Poem a4; 188 Other a5; 189 string flag; 190 cout << "\nNow Inpt!!\nWord:"; 191 cin >> a1; 192 cout << "vedio:"; 193 cin >> a2; 194 cout << "Record:"; 195 cin >> a3; 196 cout << "Poem:"; 197 cin >> a4; 198 cout << "Other:"; 199 cin >> a5; 200 cout << "Please enter the word you want to find:"; 201 cin >> flag; 202 cout << a1.CountWords(flag) << endl 203 << a2.CountWords(flag) << endl 204 << a3.CountWords(flag) << endl 205 << a4.CountWords(flag) << endl 206 << a5.CountWords(flag) << endl; 207 return 0; 208 }
标签:检索 测试 stream virt clu flag day main tac
原文地址:https://www.cnblogs.com/FlyerBird/p/9074919.html