GithubHelp home page GithubHelp logo

jieba's Introduction

jieba in spark

build jieba Tokenizer in Worker from memory.

Build jieba instance in Driver

import jieba
# initialize segment model
cut_model = jieba.Tokenizer()
cut_model.initialize()
FREQ, total, initialized = cut_model.dump_kernel()

and broadcast:

# 使用两个广播变量来广播jieba的两个模型数据
broadcast_FREQ = sc.broadcast(FREQ)
broadcast_total = sc.broadcast(total)

Read broadcast variable in Worker

seg_model = jieba.Tokenizer(FREQ=broadcast_FREQ.value, total=broadcast_total.value)
[w for w in seg_model.cut(text, HMM=True) if len(w) > 1]

Example

# -*- coding: utf-8 -*-

import jieba

#确定不与site-package里的jieba混淆
print jieba.__file__

def main():
    # initialize segment model
    cut_model = jieba.Tokenizer()
    cut_model.initialize()

    cut_list = cut_model.cut("王者荣耀和绝地求生是两款很火的游戏!")
    print "/ ".join(cut_list)

    cut_model.add_word("王者荣耀")
    cut_model.add_word("绝地求生")
    FREQ, total, initialized = cut_model.dump_kernel()
    seg_model = jieba.Tokenizer(FREQ=FREQ, total=total)

    seg_list = seg_model.cut("王者荣耀和绝地求生是两款很火的游戏!")
    print "/ ".join(seg_list)

if __name__ == "__main__":
    main()

jieba's People

Contributors

stemon avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.