C++新闻检索类
研究长字符串快速全文检索技术,实现某电力公司新闻中心新闻稿件全文检索统计系统。
1、 设计实现适合新闻稿件的基础类库
2、 新闻稿件全文检索功能实现
3、 新闻稿件按照关键字统计查询
Paper.h
#pragma once
#ifndef PAPER_H
// we're here only if PAPER_H has not yet been defined
#define PAPER_H // Definition of PAPER_H class and related functions goes here
#include <iostream>
#include <string>
#include <vector>
#define For(o,n) for (int i = 0; i < n; i++)
using namespace std;
class Paper {
protected:
int yy, mm, dd;
string unite;
string title;
//there declarations for kinds of news
public:
friend istream& operator >> (istream&, Paper&);
friend ostream& operator <<(ostream&, const Paper &);
Paper();
Paper(const Paper &asp);
virtual ~Paper() {}
void SetYMDear(const int year, const int month, const int day);
int GetYear()const;
int GetMonth()const;
int GetDay()const;
string GetTitle()const;
string GetUnite()const;
void SetUnite(const string Unite);
void SetTitle(const string Title);
virtual int CountWords(const string text) = ;
};
class Word :virtual public Paper {
protected:
string contain;
public:
friend istream& operator >> (istream&, Word&);
friend ostream& operator <<(ostream&, const Word &);
Word();
Word(const string con);
~Word() { }
int CountWords(const string text);
};
class vedio :virtual public Paper {
protected:
string act;
string Vname;
public:
friend istream& operator >> (istream&, vedio&);
friend ostream& operator <<(ostream&, const vedio&);
vedio();
~vedio() {}
vedio(const string ac, const string vn);
string GetAct()const;
string GetVName()const;
int CountWords(const string text);
};
class Record :virtual public vedio {
protected:
string ReName;
public:
friend istream& operator >> (istream&, Record&);
friend ostream& operator <<(ostream&, const Record &);
Record();
~Record() {}
Record(const string re);
int CountWords(const string text);
};
class Poem :virtual public Word {
public:
Poem() {}
~Poem() {}
int CountWords(const string text);
};
class Other :virtual public Word {
public:
Other() {}
~Other() {}
int CountWords(const string text);
};
#endif
Realize.h
#include"Paper.h"
istream& operator >> (istream&in, Paper&rhp) {
in >> rhp.yy >> rhp.mm >> rhp.dd >> rhp.title >> rhp.unite;
in.ignore();
//getline(in, rhp.contain);
return in;
}
ostream& operator <<(ostream&out, const Paper &rhp) {
out << rhp.yy << endl
<< rhp.mm << endl
<< rhp.dd << endl
<< rhp.title << endl
<< rhp.unite << endl;
// << rhp.contain << endl;
return out;
}
Paper::Paper() :yy(), mm(), dd(), unite("xxx"), title("!!!") {}
Paper::Paper(const Paper &asp) { yy = asp.yy; mm = asp.mm; dd = asp.dd; unite = asp.unite; title = asp.title; }
void Paper::SetYMDear(const int year, const int month, const int day) { yy = year, mm = month, dd = day; }
void Paper::SetTitle(const string Title) { title = Title; }
void Paper::SetUnite(const string Unite) { unite = Unite; }
int Paper::GetDay()const { return dd; }
int Paper::GetYear()const { return yy; }
int Paper::GetMonth()const { return mm; }
string Paper::GetTitle()const { return title; }
string Paper::GetUnite()const { return unite; } istream& operator >> (istream&in, Word&rhp) {
in >> rhp.yy >> rhp.mm >> rhp.dd >> rhp.title >> rhp.unite;
in.ignore();
getline(in, rhp.contain);
return in;
}
ostream& operator <<(ostream&out, const Word &rhp) {
out << rhp.yy << endl
<< rhp.mm << endl
<< rhp.dd << endl
<< rhp.title << endl
<< rhp.unite << endl
<< rhp.contain << endl;
return out;
}
Word::Word() :contain("xxx") { }
Word::Word(const string con) { contain = con; }
int Word::CountWords(const string text) {
int ans = ;
auto pos = contain.find(text);
while (pos != string::npos) {
ans++;
pos = contain.find(text, ++pos);
}
return ans;
}
istream& operator >> (istream&in, vedio&rhp) {
in >> rhp.yy >> rhp.mm >> rhp.dd >> rhp.title >> rhp.unite >> rhp.Vname;
in.ignore();
getline(in, rhp.act);
return in;
}
ostream& operator <<(ostream&out, const vedio &rhp) {
out << rhp.yy << endl
<< rhp.mm << endl
<< rhp.dd << endl
<< rhp.title << endl
<< rhp.unite << endl
<< rhp.act << endl
<< rhp.Vname << endl;
return out;
}
vedio::vedio() :act("xxx"), Vname("XXXX") {}
vedio::vedio(const string ac, const string vn) { act = ac, Vname = vn; }
string vedio::GetAct()const { return act; }
string vedio::GetVName()const { return Vname; }
int vedio::CountWords(const string text) {
int ans = ;
int pos = act.find(text);
while (pos != string::npos) {
ans++;
pos = act.find(text, ++pos);
}
return ans;
}
istream& operator >> (istream&in, Record&rhp) {
in >> rhp.yy >> rhp.mm >> rhp.dd >> rhp.title >> rhp.unite >> rhp.ReName;
in.ignore();
getline(in, rhp.act);
return in;
}
ostream& operator <<(ostream&out, const Record &rhp) {
out << rhp.yy << endl
<< rhp.mm << endl
<< rhp.dd << endl
<< rhp.title << endl
<< rhp.unite << endl
<< rhp.act << endl
<< rhp.ReName << endl;
return out;
}
Record::Record() :ReName("XXXX") {}
Record::Record(const string re) { ReName = re; }
int Record::CountWords(const string text) {
return vedio::CountWords(text);
}
int Poem::CountWords(const string text) {
int ans = ;
string flag = GetTitle();
auto pos = flag.find(text);
while (pos != string::npos) {
ans++;
pos = flag.find(text, ++pos);
}
return ans;
}
int Other::CountWords(const string text)
{
int ans = ;
string flag = GetTitle();
auto pos = flag.find(text);
while (pos != string::npos) {
ans++;
pos = flag.find(text, ++pos);
}
return ans;
}
void ShowSTD() {
cout << "Please input kinds of News in follow fomat." << endl
<< "Word or Poem or Other News:" << endl
<< "Year Month Day Title Unite\nContain(Contain at the end of ENTER)" << endl
<< "vedio or Record News:" << endl
<< "Year Month Day Title Unite Filename\nAbstract(Abstract at the end of ENTER)" << endl;
}
test.cpp
#include"Realize.h"
int main() {
ShowSTD();
Paper *tp[];
Word a1;
vedio a2;
Record a3;
Poem a4;
Other a5;
string flag;
int n = ;
cout << "\nNow Inpt!!\nWord:";
cin >> a1;
tp[] = &a1;
cout << "vedio:";
cin >> a2;
tp[] = &a2;
cout << "Record:";
cin >> a3;
tp[] = &a3;
cout << "Poem:";
cin >> a4;
tp[] = &a4;
cout << "Other:";
cin >> a5;
tp[] = &a5;
cout << "Please enter the word you want to find:";
cin >> flag;
For(o, n)cout << tp[i]->CountWords(flag) << endl;
cout << endl;
For(o, n)cout << *(tp[i]) << endl;
return ;
}

C++新闻检索类的更多相关文章
- 新闻娱乐类APP的后端核心逻辑总结
一.主要功能: 用户:登录.注册(微信账号登录.手机号登录).修改.审核 内容:发布.审核.分享.点赞.收藏及置顶热推等相关操作 评论:发布.审核.点赞及热评等相关操作 消息推送:站内信如用户修改结果 ...
- hibernate提供的5种检索数据方式
一.五种检索数据方式 1.OID检索,即使用session.get或session.load通过类及指定id查询数据,如Customer c=(Customer)session.get("C ...
- android122 zhihuibeijing 新闻中心NewsCenterPager加载网络数据实现
新闻中心NewsCenterPager.java package com.itheima.zhbj52.base.impl; import java.util.ArrayList; import an ...
- 编写利用Fragment创建新闻列表
编写利用Fragment创建新闻列表 1.创建新闻实体类News,代码如下: public class News { private String title; private String co ...
- 百度地图LBS云平台读写数据操作类
最近写了个叫<行踪记录仪>的手机软件,用了百度云来记录每个用户的最近位置,以便各用户能在地图上找到附近的人,为此写了个类来读写数据,大致如下: import java.util.Array ...
- 用react开发一个新闻列表网站(PC和移动端)
最近在学习react,试着做了一个新闻类的网站,结合ant design框架, 并且可以同时在PC和移动端运行: 主要包含登录和注册组件.头部和脚部组件.新闻块类组件.详情页组件.评论和收藏组件等: ...
- PYTHON:新闻聚合
这个项目看了有段时间,因为一直没跑通,而且关于NNTP也不是特别理解.这里是转载code123的分析. 原文地址:http://www.code123.cc/1327.html 书中的第四个练习,新闻 ...
- Python3从零开始爬取今日头条的新闻【二、首页热点新闻抓取】
Python3从零开始爬取今日头条的新闻[一.开发环境搭建] Python3从零开始爬取今日头条的新闻[二.首页热点新闻抓取] Python3从零开始爬取今日头条的新闻[三.滚动到底自动加载] Pyt ...
- Fragment在Activity中跳转,实现类似新闻标题跳转新闻内容功能
1.准备的工作,新闻数据类,新闻数据适配器,适配器的布局: News.java package com.example.zps.fourfragmentbestpractice; /** * Crea ...
随机推荐
- Jedis Cluster源码分析
最近一个项目用到Jedis客户端,需要对这个客户端进行改造.看了一下Jedis Cluster源码,做个记录 首先,说核心内容, 在Jedis源码中,关于cluster有个两个重要的map.一个是no ...
- IO流之递归
递归: 递归,指在当前方法内调用自己的这种现象 public void method(){ System.out.println(“递归的演示”); //在当前方法内调用自己 method(); } ...
- 洛谷P1351 联合权值(树形dp)
题意 题目链接 Sol 一道很简单的树形dp,然而被我写的这么长 分别记录下距离为\(1/2\)的点数,权值和,最大值.以及相邻儿子之间的贡献. 树形dp一波.. #include<bits/s ...
- cf888G. Xor-MST(Boruvka最小生成树 Trie树)
题意 题目链接 给出\(n\)点,每个点有一个点权\(a[i]\),相邻两点之间的边权为\(a[i] \oplus a[j]\),求最小生成树的值 Sol 非常interesting的一道题,我做过两 ...
- js变量定义提升、this指针指向、运算符优先级、原型、继承、全局变量污染、对象属性及原型属性优先级
原文出自:http://www.cnblogs.com/xxcanghai/p/5189353.html作者:小小沧海 题目如下: function Foo() { getName = functio ...
- 响应式 Web 设计 - Viewport 和手机变框变粗的问题
一个常用的针对移动网页优化过的页面的 viewport meta 标签大致如下: <meta name="viewport" content="width=devi ...
- PHP连接MySQL数据库的几种方式
PHP 5 及以上版本建议使用以下方式连接 MySQL : MySQLi :MySQLi 只针对 MySQL 数据库,MySQLi 还提供了 API 接口. PDO (PHP Data Objects ...
- 【阿里云产品公测】简单粗暴30S完成PTS测试配置附tornado服务器测试结果
作者:阿里云用户morenocjm [阿里云产品公测]简单粗暴 30S完成PTS测试配置(附tornado服务器测试结果) -------------------------------------- ...
- Android StickHeaderRecyclerView - 让recyclerview头部固定
介绍在项目中有时会需要recyclerview滑动式时某个view滑出后会固定在头部显示,比较常用的比如手机联系人界面.地区选择界面等. StickHeaderRecyclerView就是实现这个功能 ...
- RePlugin 插件化-内置加载
PS:插件化是什么这里就不再说了,从这里开始两种加载方式中的一种(内置加载),该框架是奇虎360开发的,官方给出优点 RePlugin是一套完整的.稳定的.适合全面使用的,占坑类插件化方案.我们&qu ...