特定用户QQ群聊天记录导出的实现
一、把QQ群的聊天记录txt格式导出
二、详细代码
1. head.h
#ifndef TxtSearch
#define TxtSearch #include<string>
#include<map>
#include<set>
#include<iostream>
#include<vector>
#include<fstream>
#include<sstream>
#include<ctype.h> typedef unsigned char BYTE;
typedef unsigned short WORD; bool IsChineseChar(WORD DoubleByte); void WordAndChar_print(std::string ); class TextQuery
{
public: typedef std::vector<std::string>::size_type line_no; void read_file(std::ifstream & );
std::set<line_no> run_query(const std::string&) const;
std::string text_line(line_no) const;
private:
void store_file( std::ifstream & );
void build_map(); std::vector<std::string> lines_of_text;
std::vector<std::string> bak_lines_of_text;
std::map< std::string,std::set<line_no> > word_map; }; void print_resluts(const std::set< TextQuery::line_no> & ,
const std::string & , const TextQuery &); #endif
2、function.cpp
#include"head.h" bool IsChineseChar(WORD DoubleByte)
{
return ( (DoubleByte < ) || (DoubleByte > ) );
} void TextQuery::read_file( std::ifstream & is)
{
store_file(is);
build_map();
} std::set<TextQuery::line_no> TextQuery::run_query(const std::string& str) const
{
std::map<std::string, std::set<line_no> >::const_iterator
loc = word_map.find(str); if(loc == word_map.end())
{
return std::set<line_no>();
} return loc->second;
}
std::string TextQuery::text_line(line_no line_num) const
{
if(line_num < lines_of_text.size())
return lines_of_text[line_num]; throw std::out_of_range("line num is out of range");
} void TextQuery::store_file(std::ifstream & is)
{
std::string txtline;
while(std::getline(is,txtline))
{
lines_of_text.push_back(txtline);
int len = txtline.length();
for(int i = ; i <len ; i ++) //pretreatment
{
bool b1 = ,b2 =;
if(!IsChineseChar(txtline[i])
&&!isalnum(txtline[i]) )
txtline[i] = ' ';
b1 = IsChineseChar(txtline[i]);
if(i + < len)
b2 = IsChineseChar(txtline[i+]);
} bak_lines_of_text.push_back(txtline);
}
} void TextQuery::build_map()
{
for(line_no line_num = ; line_num != bak_lines_of_text.size() ; ++line_num)
{
std::istringstream strline(bak_lines_of_text[line_num]);
std::string word;
while(strline >> word)
{
word_map[word].insert(line_num);
}
}
} void print_resluts(const std::set< TextQuery::line_no> & ss,
const std::string & str, const TextQuery &tq)
{
typedef std::set< TextQuery::line_no> lineset; lineset::size_type size = ss.size();
std::string path = str + ".txt";
std::ofstream outfine(path);
outfine<<str<<" occurs "<<size <<"times"<<std::endl;
lineset::const_iterator it = ss.begin(); for(; it != ss.end() ; ++ it)
{
outfine<<"\t( line "<<(*it)+<<" )"<<tq.text_line(*it)<<std::endl;
outfine<<"\t( line "<<(*it)+<<" )"<<tq.text_line(*it+)<<std::endl;
}
}
3、main.cpp
#include"head.h" int main()
{
std::ifstream infile("char.txt"); if(!infile.is_open())
{
printf("No input file!\n");
return -;
}
TextQuery tq;
tq.read_file(infile);
std::string query;
while (printf("enter user ID to look for:\n"),
std::cin>>query )
{
std::set<TextQuery::line_no> loc = tq.run_query(query);
print_resluts(loc,query,tq);
}
return ;
}
三、需要改进的地方
1、
for(; it != ss.end() ; ++ it)
{
outfine<<"\t( line "<<(*it)+<<" )"<<tq.text_line(*it)<<std::endl;
outfine<<"\t( line "<<(*it)+<<" )"<<tq.text_line(*it+)<<std::endl;
}
找到 用户名所在的行后, 我 直接把 用户名 所在的 下一行 作为 聊天内容,但其实 聊天内容里面 可以换行。
2、
如果 聊天 内容 里面 出现 用户名,会 误以为 是 用户名 所在的行,把这行输出 并把 下一行 输出。
特定用户QQ群聊天记录导出的实现的更多相关文章
- QQ群聊天记录文件分割
嗯,如题 是个蛋疼物 目前QQ的聊天记录导出功能很让人郁闷 三种聊天记录格式的导出 1 TXT 没图 2 BAK 只能再导入QQ使用 3 MHT 有图有字,缺点是一旦聊天记录很多,文件体积 ...
- 使用 R 语言挖掘 QQ 群聊天记录
1.获取数据 从 QQ 消息管理器中导出消息记录,保存的文本类型选择 txt 文件.这里获取的是某群从 2016-04-18 到 2016-05-07 期间的聊天记录,记录样本如下所示. 消息记录(此 ...
- 一梦江湖费六年——QQ群聊天分析
本文结构: 一.那些年我们加过的QQ群 二.数据读入和整理(一)--来自蓝翔的挖掘机 二.数据读入和整理(二)--你不知道的事 三.聊天宏观(1)--寤寐思服 三.聊天宏观(2)日月篇 三.聊天宏观( ...
- 安卓QQ聊天记录导出、备份完全攻略
发到知乎竟然被删掉,我也不知道我到底违反了哪条.唉,别人的毕竟是别人的.虽然博客园也是别人的 前言 我对聊天记录的备份比较执着,也在这上面折腾过不少.碰到过不少令人头疼的麻烦,在这里分享一下经验. 关 ...
- 编写Java程序,使用 Socket类模拟用户加入 QQ 群时,QQ 小冰发送欢迎消息的场景(用户充当客户端,QQ 小冰充当服务端)
查看本章节 查看作业目录 需求说明: 小冰是微软公司研发的人工智能机器人,被腾讯公司加入 QQ 群后,立即受到千万网友的喜爱.现在使用 Socket类模拟用户加入 QQ 群时,QQ 小冰发送欢迎消息的 ...
- 前端资料QQ群交流
转:https://github.com/jsfront/src/blob/master/qq.md 这本来是我QQ群内部的一份公共约定的日常交流规则,后来得到大伙的一致认可,并用实际行动来捍卫它,使 ...
- 关于iOS特定设别推送(特定用户推送)【原】
在这里,我就不哆嗦如何制作推送证书之类的了,网上一搜一大堆. 我们现在很多开发者的推送,就是集成第三方的推送SDK,然后通过第三方的推送平台帮我们进行推送.其实,这种推送(如JPush),一般只能广播 ...
- 我们是怎么管理QQ群的
文章背景:腾讯平台上的qq群数以千万百万计,但99%的在吹水扯蛋,从早上的问好开始,到晚上的晚安,无一不浪费青春之时间,看之痛心,无力改变,只好自己建了一个,希望能以此来改变群内交流的氛围或环境. 以 ...
- 关于玩QQ消息导入导出功能的感想!
今天玩了一下QQ的导入导出聊天记录的功能,感觉自己有些白痴,因为作为一个软件开发人员对自己平时使用的软件的功能掌握的不够,别说其他的任何东西了就连功能性的操作有些也不知道更别说熟练或精通了,这不是一个 ...
随机推荐
- 沈逸老师ubuntu速学笔记(2)-- ubuntu16.04下 apache2.4和php7结合编译安装,并安裝PDOmysql扩展
1.编译安装apache2.4.20 第一步: ./configure --prefix=/usr/local/httpd --enable-so 第二步: make 第三步: sudo make i ...
- SSIS 学习(1): 概要【转】
俗话说:“十年磨一剑”,Microsoft 通过5年时间的精心打造,于2005年浓重推出Sql Server 2005,这是自SQL Server 2000 以 后的又一旷世之作.这套企业级的数据库解 ...
- jsp无法支持el标签及jstl标签
在jsp页面头部添加如下 <%@ page isELIgnored="false"%> <%@ taglib uri="http://java.sun. ...
- Android异常:异步任务导致的窗口句柄泄漏问题
05-05 10:36:41.009: E/WindowManager(4243): Activity com.tao.MyActivity has leaked window com.android ...
- mac 如何进入/usr/sbin目录
1.进入terminal, 输入 ls /usr/sbin 2.在finder>前往文件夹,输入路径/usr/sbin
- 减小iOS应用程序的大小
减小iOS应用程序的大小 本文译自:Reducing the size of my App Q: 怎样才能让我的程序安装包小一点,让程序的下载和安装更快速? A: 本文收集了一些减小程序安装包大小的相 ...
- Ehcache(2.9.x) - API Developer Guide, Transaction Support
About Transaction Support Transactions are supported in versions of Ehcache 2.0 and higher. The 2.3. ...
- WebAPI GET和POST请求的几种方式
GET请求 1.无参数get请求 一般get请求有两种写法,一种是$.get() 一种是$.ajax({type:"get"}),我个人比较喜欢用后者. 下面例子主要是get无 ...
- SQL 恢复master数据库方法,没有log文件的数据库文件恢复方法
SQL Server恢复master数据库方法 第一步:复制model.mdf.mastlog.ldf.model.mdf.modellog.ldf.msdbdata.mdf.msdblog.ldf文 ...
- Javascript之改变盒子颜色
index.html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...