zoukankan      html  css  js  c++  java
  • nltk RegexpTokenizer类:python自然语言处理

    前面的一些分词工具都是写好的的规则

    如果我们想按照自己的规则进行分词 可以使用正则分词器

    1.RegexpTokenizer类

    from nltk.tokenize import RegexpTokenizer

    text = " I won't just survive, Oh, you will see me thrive. Can't write my story,I'm beyond the archetype."

    # 实例化RegexpTokenizer 会按照正则表达式进行re.findall()
    regexp_tokenizer = RegexpTokenizer(pattern="w+")
    # 实例化RegexpTokenizer 指定gaps=True会按照正则表达式进行re.split()
    regexp_tokenizer1 = RegexpTokenizer("[s,'.]", gaps=True)
    print(regexp_tokenizer.tokenize(text))
    # ['I', 'won', 't', 'just', 'survive', 'Oh', 'you', 'will', 'see', 'me', 'thrive', 'Can', 't', 'write', 'my', 'story', 'I', 'm', 'beyond', 'the', 'archetype']
    print(regexp_tokenizer1.tokenize(text))
    # ['I', 'won', 't', 'just', 'survive', 'Oh', 'you', 'will', 'see', 'me', 'thrive', 'Can', 't', 'write', 'my', 'story', 'I', 'm', 'beyond', 'the', 'archetype']

    ---------------------
    作者:qq_41864652
    来源:CSDN
    原文:https://blog.csdn.net/qq_41864652/article/details/81505768
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    T-SQL查询语句
    数据库和表的管理
    数据库概念
    IRF2实验
    IFR2笔记
    校园网双网出口实验案例
    双机热备实验
    华为H3C(NAT)实验
    BGP(边界网关协议)实验
    Hybrid实验
  • 原文地址:https://www.cnblogs.com/btschang/p/10237021.html
Copyright © 2011-2022 走看看