web-classify 用于网页分类的python工具包

本工具包将一些常用的网页分类不同语言的相关开源软件,如ictclas,BeautifulSoup,libsvm等进行封装组合,以方便用python进行网页分类相关程序的开发。

# uitl:一些常用的开源软件包 ## ictclas:中文分词,包含词频统计,关键词提取,指纹提取等功能。不同的机器上使用,需要重新编译。

## ictclas.py:我对ictclas的python封装(其实就是简单的用python调用ictclas)

使用说明: from mypack.util.ictclas import ICTclas ic = ICTclas( text ) ic.finger() #返回text的指纹 ic.words() #返回list:[(word,num),(word,num),...]

 

## smallseg:一个轻量级开源python分词程序

使用说明: from mypack.util.smallseg.myseg import seg word_nums = seg( text ) #返回list:[(word,num),(word,num),...]

 

## htmlproc:一些常用的html处理程序

### BeautifulSoup.py 开源的html析取程序,网上文档:http://www.crummy.com/software/BeautifulSoup/documentation.zh.html

### chardet 自动编码检测与转换

### parser.py 对以上两个的封装

使用说明: pr = Parser()
if pr.parse( url ):
print pr.get_html() #返回网页的html格式 print pr.get_text().encode('utf-8') #返回网页中的字符串

### crawl.py 使用pycurl的单个网页爬取程序,由于pycurl速度并不比urllib快,所以没啥用

 

# classify:文本分类模块说明

## preprocess

### chi:卡方特征选择

#### input:

  1. df_tb
格式如下,book为word在book类的文档频率(int),total为各类的df之和,为word的总df: word|book|edu|finance|house|mil|sport|car|ent|game|lady|mobile|tech|total
2. min_df

 

### tfidf:计算tfidf

### 使用说明

  1. config.py中设置所有的变量
2. 执行db/create.py,创建数据库表 3. 爬取url 4. 执行chi模块:去低频词、卡方值计算、idf值计算 from mypack.classfiy.preprocess.chi import chi_compute chi_compute() 5. 执行卡方特征选择,构建新字典 from mypack.classify.preprocess.voca import read_voca,transform_samples voca = read_voca() transform_samples( voca ) 6. 预测 from mypack.classify.svm.predict import classify_text#对文本进行分类 from mypack.classify.svm.predict import classify_text#对url进行分类

 

## svm 里面有个predict.py,就是用svm来对网页进行分类,字典和已经训练好的svm 模型放在data/下

如果要自己训练的话,自己下libsvm。liblinear用python不方便调用。

 

# web_content_extract 网页正文提取

## 使用说明

from mypack.web_content_extract.extract import Extractor extr = Extractor( url ) if extr.is_content_page(): #判断是否是正文页面
text = extr.get_content() # 提取正文
html = extr.get_content_with_format() #带html标签的正文
images = extr.get_images() # 提取正文中的图片 title = extr.get_title() # 提取正文的标题
confidence = extr.get_confidence() #是正文的置信度
extr.get_detail()#详细分析信息

 

# NOTICE ## ictclas使用前,需要先编译,如果是64位平台,先 ln -s ictclas ictclas64 ## libsvm.so 64位平台,需要先下载好libsvm,重新编译libsvm.so替换原来的

posted on 2012-05-16 18:06  lexus 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lexus/archive/2012/05/16/2504457.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值