• webclassify 用于网页分类的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
    2. 格式如下,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替换原来的

  • 相关阅读:
    node.js 基础篇
    node.js 开发环境搭建
    Velocity VelocityEngine 支持多种loader 乱码问题
    tomcat集群及session共享
    上海支付宝终面后等了两周,没能收到offer却来了杭州淘宝的电话面试
    支付宝hr终面,忐忑的等待结果
    mysql 数据范围总结
    rsync同步文件(多台机器同步代码...)
    linux基础命令
    路飞学城项目之前后端交互,跨域问题
  • 原文地址:https://www.cnblogs.com/lexus/p/2504457.html
Copyright © 2020-2023  润新知